linux常用命令(四)

2026-02-07 16:31:48

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

linux常用命令(四)

2、打印以north开头的行

-n: 取消默认的输出

sed -n '/^north/p' testfile.txt 

linux常用命令(四)

3、列出第5-7行

sed -n '5,7p' testfile.txt 

linux常用命令(四)

4、删除第三行

cat testfile.txt | sed '3d'

linux常用命令(四)

5、删除2~5行

cat testfile.txt | sed  '2,5d'  

linux常用命令(四)

6、删除所有包含north的行

cat testfile.txt | sed  '/north/d'

linux常用命令(四)

7、在第二行后(即加在第三行)加上"nihao"

sed '2a nihao' testfile.txt 

linux常用命令(四)

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
相关推荐
  • 阅读量:194
  • 阅读量:54
  • 阅读量:72
  • 阅读量:44
  • 阅读量:146
  • 猜你喜欢