Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Surround all lines in a text file with quotes ('something')

I've got a list of directories that contain spaces.

I need to surround them with ' ' to ensure that my batch scripts will work.

How can one surround each new line with a ' and a ' (quotes).

e.g.

File1:

/home/user/some type of file with spaces /home/user/another type of file with spaces 

To

File2:

'/home/user/some type of file with spaces' '/home/user/another type of file with spaces' 
like image 216
user191960 Avatar asked Oct 24 '09 00:10

user191960


People also ask

How do you replace double quotes in Notepad ++?

The easiest way to do this is to highlight one of the quotes, then select Search, then Replace. You will see the Find What field is already filled in with the quote you selected. I suggest have Search mode set to normal. Make sure the Replace With field is empty.


1 Answers

Use sed?

sed -e "s/\(.*\)/'\1'/" 

Or, as commented below, if the directories might contain apostrophes (nightmare if they do) use this alternate

sed -e "s/'/'\\\\''/g;s/\(.*\)/'\1'/" 
like image 55
martin clayton Avatar answered Sep 21 '22 18:09

martin clayton