How can I delete a newline if it is the last character in a file?
Posted
by Todd Partridge
on Stack Overflow
See other posts from Stack Overflow
or by Todd Partridge
Published on 2009-10-31T10:42:19Z
Indexed on
2010/03/20
7:51 UTC
Read the original article
Hit count: 244
I have some files that I'd like to delete the last newline if it is the last character in a file. 'od -c' shows me that the command I run does write the file with a trailing new line:
0013600 n t > \n
I've tried a few tricks with sed but the best I could think of isn't doing the trick:
sed -e '$s/\(.*\)\n$/\1/' abc
Any ideas how to do this?
© Stack Overflow or respective owner