Reputation: 143
I am trying to remove the last newline added to the file using bash script.
I have got this -
truncate -s $(($(stat -c '%s' foo.txt)-1)) foo.txt
here foo.txt the file name. but I want to parametrize the file name, I will pas the file name to the script and it should this remove the newline at last from that file. Request your help on this. I do not have linux in my machine and tried using cygwin but it is giving error while running the script.
Thanks
Upvotes: 2
Views: 1611
Reputation: 784908
To remove last line if it is newline use this sed
L
sed -i.bak '/^[[:blank:]]*$/{$d;}' foo.txt
Upvotes: 1