你好我正在处理一个如下文件:
AliceBlue
AntiqueWhite
Aqua
Aquamarine
Azure
Beige
Bisque
Black
BlanchedAlmond
Blue
BlueViolet
Brown
我想从另一个列表中获得具有以下结构的列表:
"AliceBlue","AntiqueWhite","Aqua",...,
为了达到这个目的,我试过了:
awk -vORS=, '{ print $1 }' listColors.txt | sed 's/,$/\n/'
我得到了:
AliceBlue,AntiqueWhite,...,
我几乎实现了我想要的但我认为我需要构建一个正则表达式来为所有单词添加双引号,我不是正则表达式的专家,我想欣赏任何完成任务的建议。
答案 0 :(得分:3)
使用awk
即可:
awk -v ORS=, '{$1= "\"" $1 "\""} 1' file; echo
"AliceBlue","AntiqueWhite","Aqua","Aquamarine","Azure","Beige","Bisque","Black","BlanchedAlmond","Blue","BlueViolet","Brown",