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で開くことができ、その表示が2列に表示されるように

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 に答える