Loading...

Bash cut .csv files

Answer #1 100 %

Given your example:

$ awk -F, '{print $6}' file
Basildon
Parkville                   
Astoria                     
Echuca
Cahaba Heights              
Mickleton                   
Peoria                      
Martin                      
Tel Aviv
Chatou

Or with cut:

$ cut -d, -f 6 file 
# same output

Or, for all fields up to and including the 6th:

$ awk 'BEGIN{FS=OFS=","} {for (i=1;i<=6;i++) printf "%s%s", $i, i==6 ? ORS : OFS}' file

Or, cut version:

$ cut -d, -f-6 file 

You’ll also like:


© 2022 CodeForDev.com -