Skip to content

Instantly share code, notes, and snippets.

@bongkook
Created April 12, 2014 02:42
Show Gist options
  • Save bongkook/10516134 to your computer and use it in GitHub Desktop.
Save bongkook/10516134 to your computer and use it in GitHub Desktop.
CSV形式ファイルに列(Column)を追加するAWKスクリプト ref: http://qiita.com/bongkook/items/9748c7114983056f4c88
#!/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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment