Selecting Columns from CSV file

technotes
Oct 12, 2021
gawk -vFPAT='([^,]*)|("[^"]+")' -vOFS=,  '{print $1","$2","$4","$7}' yourfile.csv
  1. -vOVFS=,part means use , as a separator
  2. -vFPAT allows your csv file to contain double quotes, which can contain , which would confuse awk as a separator
  3. why “gawk”? Not all OS’s awk has the -vFPAT capability. MacOS’s default awk doesn’t. Use brew install gawk to get yours.

--

--