Last active
October 18, 2016 18:01
-
-
Save HeLiBloks/34dd502cb71507a6a3c8 to your computer and use it in GitHub Desktop.
gawk awk hawk
This file contains 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
#print occurrance off ;,|[:TAB:] | |
#this might be the delim | |
awk -vFS="" '{for(i=1;i<=NF;i++){ if($i~/[,;| ]/) { w[tolower($i)]++} } }END{for(i in w) print i,w[i]}' file.csv |sort -n|head -1|cut -f1 -d" " | |
#find longest line | |
awk -F"$DELIM" '{ if ( length > L ) { L=length} }END{ print L}' $1 | |
#fix commas after quotes, good for cleaning csv files | |
awk -F'"' -v OFS='' '{ for (i=2; i<=NF; i+=2) gsub(",", "", $i) } 1' $1 | |
#print records between BEGIN,END | |
awk '$1 == "BEGIN", $1 == "END"' | |
#convert csv to json | |
awk -F, 'BEGIN{print "{"} {if (notfirst) {print ","}; print "\"" $1 "\":\"" $2 "\""; notfirst=1} END {print "\"\":\"\"}" }' input.csv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment