Bash - awk

gawk Documentation

  1. Check number of columns: -F “,” specifies field separator as comma
awk -F "," '{print NF}' uniqMovie.csv | head -1
  1. Filter the data to get only 1st, 2nd, 6th and last column
awk 'BEGIN{FS=",";OFS=",";}{print $1,$2,$6,$NF}' uniqMovie.csv > newMovie.csv`
  1. Use awk to rearrange columns
awk '{print $2 " " $1}' file.txt
  1. Sum column one from a file
awk '{s+=$1} END {print s}' mydatafile
  1. One of my awk aliases is the mean and sd of column 1
awk '{s+=$1;s2+=($1$1)} END {print s/NR,sqrt((NRs2-ss)/(NR(NR-1)))}'
  1. A handy alias for summing up a column of numbers from the command line:
sumcol='awk '\''{ SUM += $1} END { print SUM}'\'