Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add quotation marks to each word in a file

I have some words separated by commas in a file, such as below:

variable1, variable2, variable3, variable4

What's the easiest way to use BASH for adding quotation marks to each word?

The end result should look like:

"variable1", "variable2", "variable3", "variable4"
like image 567
jitter Avatar asked Sep 12 '25 09:09

jitter


1 Answers

Simply with sed:

sed 's/[^[:space:],]\+/"&"/g' file

The output:

"variable1", "variable2", "variable3", "variable4"
like image 197
RomanPerekhrest Avatar answered Sep 14 '25 01:09

RomanPerekhrest