Originally published at: https://www.cyberciti.biz/faq/sed-remove-last-character-from-each-line/
I need to remove the last character from a line and shell variable such as “${_allowed_ips}”. For example, each line is as follows in my file:
foo,
bar,
demo,
I need output as follows:
foo
bar
demo.
How can I use sed to delete the last character?
if it s aways ,
sed -i s/,$//g file
if you want to remove the last character
sed -i s/.$//g file