Reputation: 3183
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 change in sed
syntax in order to remove the line number
only if it exist in the last line of the file?
Upvotes: 29
Views: 37965
Reputation: 1291
For those who are on SunOS which is non-GNU, the following code will help:
sed '$d' tmp.dat > test.dat
Upvotes: 4
Reputation: 17757
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.
Upvotes: 52