+2 votes
in Operating Systems by (14.2k points)

I tried "awk 'END{print FNR}' filename" to count the number of records in a file that is gzipped, but it gave the wrong count. What is the correct way to find the number of records in a zipped file?

1 Answer

+1 vote
by (22k points)

Yes, if you run the above command to count the records in a zipped file, you will get the wrong count.

The simple way to count the number of records is: "zcat filename | awk command". You can use one of the following commands:

$ zcat zipped_file | awk 'END{print NR}'

$ zcat zipped_file | awk 'END{print FNR}'

$ zcat zipped_file | awk '{i++;}END{print i}'

$ zcat zipped_file | awk 'BEGIN{i=0}{i++}END{print i}'

...