Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete character from last line only 1

Status
Not open for further replies.

vodkadrinker

Technical User
May 16, 2002
163
GB
I want to delete a <cntrl>+<M> from only the last line of a file, is there an easy sed statement for this?
 
To delete the last char of the last line:
sed '$s!.$!!' /path/to/input > output
To delete all ^M from the last line:
cr=$(echo "\r\c") sed '$s!'"$cr"'!!g' /path/to/input > output
To delete first ^M from the last line:
cr=$(echo "\r\c") sed '$s!'"$cr"'!!' /path/to/input > output

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top