I have text file with something like
first line
line nr 2
line three
etc
And i want to generate
"first line",
"line nr 2",
"line three",
I wonder how to do this in python or maybe in bash if it’s easier/quicker. I know there is different code for opening file and different for reading only one line in python(?) but i’m not sure which option to use in this case and, more importantly, how to add these characters. Any advice would help.
A number of easy ways to do it…
A simple perl oneliner:
To explain a bit, the regex
^(.*)$grabs everything (the(.*)) between the start of the line (^) and the end of the line ($), then uses the$1match group variable to reconstruct it with the quotes and comma.