linux常用命令(四)
1、文本如下
[root@localhost shell]# cat testfile.txt
northwest NW Charles Main 3.0 .98 3 34
northwest NW Charles Main 3.0 .98 3 34
western WE Sharon Gray 5.3 .97 5 23
southwest SW Lewis Dalsass 2.7 .8 2 18
southern SO Suan Chin 5.1 .95 4 15
southeast SE Patricia Hemenway 4.0 .7 4 17
eastern EA TB Savage 4.4 .84 5 20
northeast NE AM Main Jr. 5.1 .94 3 13
northeast NE AM Main Jr. 5.1 .94 3 13
north NO Margot Weber 4.5 .89 5 9
north NO Margot Weber 4.5 .89 5 9
central CT Ann Stephens 5.7 .94 5 13

2、打印以north开头的行
-n: 取消默认的输出
sed -n '/^north/p' testfile.txt

3、列出第5-7行
sed -n '5,7p' testfile.txt

4、删除第三行
cat testfile.txt | sed '3d'

5、删除2~5行
cat testfile.txt | sed '2,5d'

6、删除所有包含north的行
cat testfile.txt | sed '/north/d'

7、在第二行后(即加在第三行)加上"nihao"
sed '2a nihao' testfile.txt
