linux 系统如何删除特定的行

1、vi编辑

      首先利用   vi filenae 查看文件,  在命令行模式下 使用  :g/string/d    执行命令即可删除含有 string字符串的行 ,其中string为字符串

 

2、sed

 

[root@centos7 test2]# seq 15 > a.txt
[root@centos7 test2]# ls
a.txt
[root@centos7 test2]# cat a.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@centos7 test2]# sed '/2/d' a.txt
1
3
4
5
6
7
8
9
10
11
13
14
15

 

 

3、grep

[root@centos7 test2]# ls
a.txt
[root@centos7 test2]# cat a.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@centos7 test2]# grep -v "2" a.txt
1
3
4
5
6
7
8
9
10
11
13
14
15

 

4、awk

[root@centos7 test2]# ls
a.txt
[root@centos7 test2]# cat a.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@centos7 test2]# awk '!/2/{print $0}' a.txt
1
3
4
5
6
7
8
9
10
11
13
14
15

 

posted @ 2020-05-08 06:58  小鲨鱼2018  阅读(2971)  评论(0编辑  收藏  举报