Bash working code to delete first or last line from file

前端 未结 7 1869
面向向阳花
面向向阳花 2021-01-11 10:31

I saw the sed examples, but no matter how I write that it won\'t delete my first line. Actually, I did more tests and it won\'t delete my first line either, so

相关标签:
7条回答
  • 2021-01-11 11:10

    Because nobody gives it any love:

    ed filename <<'END'
    1d
    $d
    w
    q
    END
    
    0 讨论(0)
  • 2021-01-11 11:13

    You can use the --in-place (-i) switch:

    sed -i '$d' filename
    

    Source: man sed

    0 讨论(0)
  • 2021-01-11 11:14

    If your sed supports in-place editing, it's sed -e '1d' -e '$d' -i filename.

    0 讨论(0)
  • 2021-01-11 11:14

    Try cat file1 | sed "1,1d; $d" > file2

    0 讨论(0)
  • 2021-01-11 11:21

    sed -i '$ d' filename. The -i flag edits file in place.

    0 讨论(0)
  • 2021-01-11 11:23

    Giving this answer since sed is not tagged.

    head -`wc -l test2.cc | awk '{print ($1-1)}'` test2.cc
    
    0 讨论(0)
提交回复
热议问题