タブ区切りのCSVを「」に変換し、値が空の場合はスペースを追加したいと思います。
FirstName LastName Address1 Address2 City State ZIP
John1 Mark 149 Lower Stereet California CA 05478
John2 Mark 149 Lower, Stereet California CA 05478
John3 Mark 149 ,Lower Stereet California CA 05478
希望の結果として
"FirstName","LastName","Address1","Address2","City","State","ZIP"
"John1","Mark","149 Lower Stereet", ,"California","CA","05478"
"John2","Mark", ,"149 Lower, Stereet","California","CA","05478"
"John3","Mark","149,Lower Stereet", , "California","CA","05478"
次のコマンドを試してみました。
sed 's/\t\+/,/g;s/^\|$/"/g;s/,/"&"/g' Actual.csv > Actual_V6.csv
出力
"FirstName","LastName","Address1","Address2","City","State","ZIP
"
"John1","Mark1","149 Lower Stereet","California","CA","05489
"
"John2","Mark","149 Lower"," Stereet","California","CA","05489","
"
"John3","Mark","149 ","Lower Stereet","California","CA","05489"
どこ
- 「149、Lower Stereet」は「149 Lower」に変換され、「Stereet」は「149 Lower、Stereet」に変換する必要があります。
- 追加する」
- NULL値を認識しません。
編集する
出力hexdump
:
ベストアンサー1
以下を使用できます。
sed 's/\t/","/g; s/.*/"&"/; s/""/ /g' file
s/""/ /g
適切なcsvは必ずしも必要ではありませんが、必要な出力を得るために必要です。
あなたが持っている場合csvtool
:
csvtool -t TAB -u ',' cat file
必要な場合にのみフィールドを参照します。