zoukankan      html  css  js  c++  java
  • linux系统中如何删除第一行、前两行,最后一行、最后两行

    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
  • 相关阅读:
    2013第47周日整理
    2013第47周六笔记本散热及相关问题思考
    myeclipse中控制台日志比实际晚8小时解决方法及java日志处理
    2013第47周五抱怨负能量
    ORM框架
    什么是IT
    内网port映射具体解释(花生壳)
    DrawText的使用
    socket编程原理
    hibernate学习——Set集合配置
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14344196.html
Copyright © 2011-2022 走看看