I am trying to add "at the beginning and ",at the end of each non-empty line a text file in Perl.
perl -pi -e 's/^(.+)$/\"$1\",/g' something.txt
It adds "at the beginning of each non-empty line, but I have a problem with ",.
Input Example:
bla
bla bla
blah
This output I get:
"bla
",
"bla bla
",
"blah
",
And for this conclusion, I really want :
"bla",
"bla bla",
"blah",
How to fix it?
Edit: I opened my output file in vim now (I opened it in kwrite before it was not visible), and I noticed that vim shows ^Mbefore each ",- I don’t know what the code adds this to.
source
share