2

My data file is as follow:

name,age,quote,children
Mary,50,Love For All, Hatred For None.,3
John,61,I think, therefore, I am,2
June,42,You're braver than you believe, and stronger than you seem, and smarter than you think,1

I'd like to extract rows where children >1, to output.txt. However I can't really specify column $4 since there's commas in the column quote.

How should I approach this? I've tried awk -F, '$-1 > 1' data > output.txt, but it doesn't read $-1 like python/java.

4

In awk, the last field value is accessible by the $NF, second last $(NF-1), etc based on the field separator. so you need

awk -F, '$NF > 1' data

Ps, and don't forget to fix the source program that produce that invalid .csv file at first place.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.