1、测试数据如下:
[root@PC3 test]# cat a.txt
1 Beijing 2003
2 Beijing 2004
3 Beijing 2005
4 Beijing 2006
5 Beijing 2007
6 Beijing 2008
7 Beijing 2007
8 Beijing 2005
9 Beijing 2006
10 Beijing 2007
11 Beijing 2008
12 Beijing 2007
2、删除第一行
[root@PC3 test]# sed 1d a.txt
2 Beijing 2004
3 Beijing 2005
4 Beijing 2006
5 Beijing 2007
6 Beijing 2008
7 Beijing 2007
8 Beijing 2005
9 Beijing 2006
10 Beijing 2007
11 Beijing 2008
12 Beijing 2007
[root@PC3 test]# tail -n +2 a.txt
2 Beijing 2004
3 Beijing 2005
4 Beijing 2006
5 Beijing 2007
6 Beijing 2008
7 Beijing 2007
8 Beijing 2005
9 Beijing 2006
10 Beijing 2007
11 Beijing 2008
12 Beijing 2007
3、删除前两行
[root@PC3 test]# sed 1,2d a.txt
3 Beijing 2005
4 Beijing 2006
5 Beijing 2007
6 Beijing 2008
7 Beijing 2007
8 Beijing 2005
9 Beijing 2006
10 Beijing 2007
11 Beijing 2008
12 Beijing 2007
[root@PC3 test]# tail -n +3 a.txt
3 Beijing 2005
4 Beijing 2006
5 Beijing 2007
6 Beijing 2008
7 Beijing 2007
8 Beijing 2005
9 Beijing 2006
10 Beijing 2007
11 Beijing 2008
12 Beijing 2007
4、删除最后一行
[root@PC3 test]# sed '$d' a.txt
1 Beijing 2003
2 Beijing 2004
3 Beijing 2005
4 Beijing 2006
5 Beijing 2007
6 Beijing 2008
7 Beijing 2007
8 Beijing 2005
9 Beijing 2006
10 Beijing 2007
11 Beijing 2008
[root@PC3 test]# head -n -1 a.txt
1 Beijing 2003
2 Beijing 2004
3 Beijing 2005
4 Beijing 2006
5 Beijing 2007
6 Beijing 2008
7 Beijing 2007
8 Beijing 2005
9 Beijing 2006
10 Beijing 2007
11 Beijing 2008
5、删除最后两行
[root@PC3 test]# head -n -2 a.txt
1 Beijing 2003
2 Beijing 2004
3 Beijing 2005
4 Beijing 2006
5 Beijing 2007
6 Beijing 2008
7 Beijing 2007
8 Beijing 2005
9 Beijing 2006
10 Beijing 2007