sed + remove string only in the last line of the file

后端 未结 2 786
萌比男神i
萌比男神i 2020-12-31 00:41

I use the following sed command to remove the line number string from file

sed -i s\'/line number//g\' file

but what I need to

相关标签:
2条回答
  • 2020-12-31 00:49

    I'm not sure I fully understand your question, however this can help you :

    sed -i '$ s/line number//g' file
    

    This will perform substitution only on last line (because of $), replacing line number by nothing.

    man sed, section Addresses can help you understand how to apply sed commands on part of the text.

    0 讨论(0)
  • 2020-12-31 01:03

    For those who are on SunOS which is non-GNU, the following code will help:

    sed '$d' tmp.dat > test.dat
    
    0 讨论(0)
提交回复
热议问题