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

Viewed 33650

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'
6 Answers

I prefer awk (it's faster than bash and very easy to extend):

awk '{print "\'" $0 "\'"}'

Using sd, to surround with ' the command looks like:

sd '(.*)' \''$1'\'

to surround with " the command looks like:

sd '(.*)' '"$1"'

Hopefully you got the idea.

Related