Created
April 12, 2014 02:42
-
-
Save bongkook/10516134 to your computer and use it in GitHub Desktop.
CSV形式ファイルに列(Column)を追加するAWKスクリプト ref: http://qiita.com/bongkook/items/9748c7114983056f4c88
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/gawk -f | |
#./add_column.awk col=[num] val=[value] quot=[true] [filename] > [new filename] | |
BEGIN{ | |
FS="," | |
} | |
{ | |
split($0,cols,","); | |
rec = "" | |
for (i=0;i<length(cols);i++) { | |
colno = (i+1) | |
if(colno==col) { | |
if(quot=="true") { | |
rec = rec ",¥"" val "¥"" | |
} else { | |
rec = rec "," val | |
} | |
} | |
if (i==0) { | |
rec = $ + colno | |
} else { | |
rec = rec "," $ + colno | |
} | |
} | |
print rec | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
あ | い | う | と | え | お | |
---|---|---|---|---|---|---|
か | き | く | と | け | こ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
あ | い | う | え | お | |
---|---|---|---|---|---|
か | き | く | け | こ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment