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" 回答1: Simply with sed : sed 's/[^[:space:],]\+/"&"/g' file The output: "variable1", "variable2", "variable3", "variable4" 回答2: It can be done with parameter expansion str="variable1, variable2, variable3, variable4" str2=\""${str//