+2 votes
in Operating Systems by (71.8k 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

+2 votes
by (346k points)
selected by
 
Best answer

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}'


...