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
  • 相关阅读:
    无锁队列以及ABA问题
    bigworld源码分析(3)——dbMgr分析
    bigworld源码分析(4)——BaseAppMgr分析
    bigworld源码分析(5)——BaseApp分析
    bigworld源码分析(2)—— loginApp分析
    bigworld源码分析(1)—— 研究bigworld的意义和目标
    C++嵌入Python,以及两者混用
    B-Tree算法分析与实现
    通过sqlserver日志恢复误删除的数据
    win7启动时怎么自动进入桌面
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14344196.html
Copyright © 2011-2022 走看看