1. grep

1.1. 常用选项

 1# 输出start到end
 2grep -o 'start.*end' file
 3# 文件作为文本处理
 4grep -a 'xxx' file
 5# 忽略二进制文件
 6grep -rsnI 'xxx' ./
 7# 递归目录
 8grep -r 'xxx' ./
 9
10# 忽略大小写(-i, --ignore-case)
11# 全词匹配(-w, --word-regexp)
12# 输出计数(-c, --count)
13# 显示行号(-n, --line-number)
14# 只列出匹配的文件名(-l, --files-with-matches)

1.2. 其他选项

1# --color:显示颜色,默认开启

2. sed示例

 1# 在第5行前插入新行
 2sed -i '5i\string' file
 3
 4# 全词匹配替换
 5sed -e 's%\<old\>%new%g' file
 6# 忽略大小写匹配替换
 7sed -e 's%\<old\>%new%ig' file
 8
 9# 输出图片链接,输出完整 "![...](...)"
10sed -n '/!\[.*\]\(.*\)/p' *.md
11sed -n 's/!\[.*\]\(.*\)/\0/p' *.md
12
13# 输出图片链接,只输出 "(...)"
14sed -n 's/!\[.*\]\(.*\)/\1/p' *.md
1sed -i \
2    -e '/^description:/a\featured: false' \
3    -e '/^image:.*/d' \
4    -e '/^hidden:/a\image:\nfigurePositionShow:\nfeatureImage:\nfeatureImageAlt:\nfeatureImageCap:\nthumbnail:\nshareImage:\ncodeMaxLines:\ncodeLineNumbers:\n' \
5    -e '/^tags:$/i\series:' \
6    $*

3. awk

4. patch

1patch -t -p 1 < patchfile.patch

5. hexdump

5.1. 按4字节显示

1hexdump -e '\"0x%08_ax: \"' -e '4/4 \"%08X \"' -e '\"\n\"'
1alias xdump='hexdump -e '\''"0x%08_ax: "'\'' -e '\''4/4 "%08X "'\'' -e '\''"\n"'\'''
 1hexdump -v -n 128 /sys/devices/platform/soc/243000.efuse/nvmem*/nvmem -e \
 2'"compat: 0x"       24/1 "%x" "\n"
 3"AICORE\t: 0x"      1/1 "%02x" "\n"
 4"compat: 0x"        43/1 "%x" "\n"
 5"DATE\t: 0x"        8/1  "%02x" "\n"
 6"compat: 0x"        32/1 "%x" "\n"
 7"===========SYSTEM SOFTWARE===========\n"
 8"board_type\t: 0x"   1/1 "%02x" "\n"
 9"bom_version\t: 0x"  2/1 "%02x" "\n"
10"ddr_info\t: 0x"     2/1 "%02x" "\n"
11"flash_info\t: 0x"   2/1 "%02x" "\n"
12"pmic\t: 0x"         3/1 "%02x" "\n"
13"pmic_sw\t: 0x"      1/1 "%02x" "\n"
14"vendor\t: 0x"       2/1 "%02x" "\n"
15"SN\t: "             4/1 "%02x" "\n"
16"others\t: 0x"       3/1 "%02x" "\n"
17' | grep DATE | awk '{print $3}' | tac -rs .. | echo "$(tr -d '\n')"

iconv