Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enclose every line in a file in double quotes with sed?

Tags:

regex

windows

sed

This is what I tried: sed -i 's/^.*/"$&"/' myFile.txt

It put a $ at the beginning of every line.

like image 726
nw. Avatar asked Jul 01 '11 23:07

nw.


People also ask

Can you use double quotes with sed?

@DummyHead Here's another approach: if you use single quotes, the sed command is exactly as you type it. If you use double quotes, you must take into account all shell substitutions and elaborations to "visualize" what command is eventually passed on to sed.

How do you use sed multiple times?

You can tell sed to carry out multiple operations by just repeating -e (or -f if your script is in a file). sed -i -e 's/a/b/g' -e 's/b/d/g' file makes both changes in the single file named file , in-place.

How do you pass a double quote in a string?

If you need to use the double quote inside the string, you can use the backslash character. Notice how the backslash in the second line is used to escape the double quote characters. And the single quote can be used without a backslash.

How do you use sed to replace single quotes?

You basically have sed 's/' followed by /"/' , which is a slash and an unclosed double quoted string. you have no such problem. This is sed 's/' followed by "'" (a double quoted single quote), followed by '/"/' .


1 Answers

here it is

sed 's/\(.*\)/"\1"/g' 
like image 106
Karoly Horvath Avatar answered Oct 22 '22 05:10

Karoly Horvath