Reputation: 19110
I'm using bash shell on Mac Yosemite. I found this command for extracting the second column of a CSV file ...
awk -F "\"*,\"*" '{print $2}'
but my quesiton is what if I want to extract both the second and second-to-last column? For simplicity, we can assume there is more than one column in the CSV data.
Upvotes: 1
Views: 119
Reputation: 784998
You can use $(NF-1)
to get second-to-last column:
awk -F '"?,"?' '{print $2, $(NF-1)}' file.csv
Upvotes: 4