0

我有这样的文件

field1****This is, sample text ", here and there"@@@@field2****This is, sample text ", here and there"@@@@field3****This is, sample text ", here and there"@@@@

**** is the field separator

@@@@ is the record separator

我想要这样的csv

field1, "This is, sample text ", here and there""

这样我就可以在 microsoft excel 中打开它并在两列中显示

4

1 回答 1

1
$ cat file
field1****This is, sample text ", here and there"@@@@field2****This is, sample text ", here and there"@@@@field3****This is, sample text ", here and there"@@@@

$ gawk -F'\\*\\*\\*\\*' -v OFS=', ' -v RS='@@@@\n?' '{$2="\"" $2 "\""}1' file
field1, "This is, sample text ", here and there""
field2, "This is, sample text ", here and there""
field3, "This is, sample text ", here and there""

$ gawk -F'\\*\\*\\*\\*' -v OFS=', ' -v RS='@@@@\n?' '{for (i=1;i<=NF;i++) $i="\"" $i "\""}1' file
"field1", "This is, sample text ", here and there""
"field2", "This is, sample text ", here and there""
"field3", "This is, sample text ", here and there""
于 2013-03-20T04:17:55.800 回答