I have a CSV file with a variable number of fields per record. How do I print lines of a certain number of fields only? Several permutations of the following (including the use of escape characters) have failed to retrieve the line I'm after (1,2,3,4)...
$ cat myfile
1,2,3,4
1,2,3
$ # Print lines made from ((one or more non commas followed by a comma) x 3)
$ nawk '/([^,]*,){3}/' myfile
$
Any ideas? Thanks in advance...
---------- Post updated at 02:48 PM ---------- Previous update was at 02:42 PM ----------
Doh!
Solution:
$ nawk -F, 'NF == 4' myfile
1,2,3,4