nl ~/text.txt | sed '2,5d' 在输出中删除2~5行的内容
nl ~/text.txt | sed '2d' 在输出中删除第2行的内容
nl ~/text.txt | sed '2, $d' 在输出中删除2~$(最后)行的内容
nl ~/text.txt | sed '2a drink tea' 在输出中删除2行后加上 drink tead 字符
nl ~/text.txt | sed '2i drink tea' 在输出中删除2行前加上 drink tead 字符
nl ~/text.txt | sed '2i drink \ >tea' 在输出中删除2行前加上 drink \n tead 两行字符
nl ~/text.txt | sed '2,5c No 2-5 number' 在输出中, 将2-5行字符替换为No 2-5 number
nl ..... | sed -n '1,3p' 输出1-3行字符
sed 's/要被替换的字符/新的字符/g'
cat /etc/man_db.config | grep 'MAN'
cat /etc/man_db.config | grep 'MAN' | sed 's/#.*$//g' 将以# 开头的换成空字符
cat /etc/man_db.config | grep 'MAN' | sed 's/#.*$//g' | sed '/^$/d' 删除空字符行
nl ~/test.txt | grep '^ *[0-9]*[[:blank:]]*test line [0-9]*'
nl ~/test.txt | sed '/^ *[0-9]*[[:blank:]]*test line [0-9]*/d' 删除和匹配的字符行
nl ~/test.txt | sed '/*test line [0-9]*/d' 效果同上句命令一致
sed 直接修改文件 sed -i function
sed -i 's/\.$/\!/g' test.txt 将test.txt中句末的'.'换成'!'
sed -i '$a #this is a test' test.txt 在test.txt文件末加上 # this is a test 字符串.
扩展的正则表达式: egrep命令, 或者grep -E 命令代替grep命令
test.txt 内容如下0
Type some words in this nano editor program!
You can use [ctrl] plus keywords to go to some function!
Bye bye~~~~!
test line 4
test line 5
test line 6
test line 7
test line 8
test line 9
test line 10
test line 11
test.txt 通过nl输出如下
1 Type some words in this nano editor program!
2 You can use [ctrl] plus keywords to go to some function!
3 Bye bye~~~~!
4 test line 4
5 test line 5
6 test line 6
7 test line 7
8 test line 8
9 test line 9
10 test line 10
11 test line 11
12 # This is a test.
随手记一记, 以后也许用不到吧!