I have this set of lines in a file:
{info},
{info},
{info},
{info},
and I want the file like this without the last ",":
{info},
{info},
{info},
{info}
How can I do it in bash? Any idea?
I have this set of lines in a file:
{info},
{info},
{info},
{info},
and I want the file like this without the last ",":
{info},
{info},
{info},
{info}
How can I do it in bash? Any idea?
You can use sed
:
sed '$ s/.$//' your_file
$
is to tell sed
to match only last lines
is for "substitute", note the empty string between the two last /
s.$
is a regex that matches the last character in the fileNote that you can use whatever separator you want instead of /
, for example you can rewrite the expression:
sed '$ s-.$--' your_file
In vim, you could use :substitute or :s to do this as well. It's a vim-built in -- you can read about it here http://vim.wikia.com/wiki/Search_and_replace
The syntax is very similar to the other posted solution, you'd go into the command mode and type in
:$s/.$//g