Skip to content

Instantly share code, notes, and snippets.

@HeLiBloks
Last active October 18, 2016 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HeLiBloks/34dd502cb71507a6a3c8 to your computer and use it in GitHub Desktop.
Save HeLiBloks/34dd502cb71507a6a3c8 to your computer and use it in GitHub Desktop.
gawk awk hawk
#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