学习致谢:
https://www.yisu.com/zixun/724766.html
[root@singleNode ~]$ cat temp.csv
1 Linux Operating System
2 Unix Operating System
3 RHEL
4 Red Hat
5 Fedora
6 Arch Linux
7 Centos
8 Debian
9 Ubuntu
10 openSUSE
sed 'Nd' file
示例1——删除第一行
[root@singleNode ~]$ sed '1d' temp.csv
2 Unix Operating System
3 RHEL
4 Red Hat
5 Fedora
6 Arch Linux
7 Centos
8 Debian
9 Ubuntu
10 openSUSE
示例2——删除最后一行
[root@singleNode ~]$ sed '$d' temp.csv
1 Linux Operating System
2 Unix Operating System
3 RHEL
4 Red Hat
5 Fedora
6 Arch Linux
7 Centos
8 Debian
9 Ubuntu
sed '5,7d' file
示例
[root@singleNode ~]$ sed '5,7d' temp.csv
1 Linux Operating System
2 Unix Operating System
3 RHEL
4 Red Hat
8 Debian
9 Ubuntu
sed '1d;5d;9d;$d' file
示例1
[root@singleNode ~]$ sed '1d;5d;9d;$d' temp.csv
2 Unix Operating System
3 RHEL
4 Red Hat
6 Arch Linux
7 Centos
8 Debian
示例2——逻辑非 ! 使用,比如删除第a到 b行以外的其他行
[root@singleNode ~]$ sed '3,6!d' temp.csv
3 RHEL
4 Red Hat
5 Fedora
6 Arch Linux
sed '/^$/d' file
sed '/System/d' file
示例——删除包含System的行
[root@singleNode ~]$ sed '/System/d' temp.csv
3 RHEL
4 Red Hat
5 Fedora
6 Arch Linux
7 Centos
8 Debian
9 Ubuntu
10 openSUSE
示例——删除以 6 开头的行
[root@singleNode ~]$ sed '/^6/d' temp.csv
1 Linux Operating System
2 Unix Operating System
3 RHEL
4 Red Hat
5 Fedora
7 Centos
8 Debian
9 Ubuntu
10 openSUSE
sed '/m$/d' file
示例——删除以 x 或 m 结尾的行
[root@singleNode ~]$ sed '/[xm]$/d' temp.csv
3 RHEL
4 Red Hat
5 Fedora
7 Centos
8 Debian
9 Ubuntu
10 openSUSE
sed '/^[A-Z]/d' file
示例
[root@singleNode ~]$ sed '/[A-Z]$/d' temp.csv
1 Linux Operating System
2 Unix Operating System
4 Red Hat
5 Fedora
6 Arch Linux
7 Centos
8 Debian
9 Ubuntu
sed '/[A-Za-z]/d' file
sed '/[0-9]/d' file