-1

I can get the count number of files in the zip but unable to exclude any files have extension metadata. How can I count only "pdf" files in the zip. I really appreciate any help you can provide.

unzip -l 0532.zip
742248    05-31-2023 15:19   /pdf/0531/CP-1960-5266M.pdf
4125      05-31-2023 15:19   /pdf/0531/CB-CB-177729.pdf.metadata
1221395   05-31-2023 15:19   /pdf/0531/CB-CB-177729.pdf
4128      05-31-2023 15:19   /pdf/0531/CP-1988-10086.pdf.metadata
243050    05-31-2023 15:19   /pdf/0531/CP-1988-10086.pdf
4125      05-31-2023 15:19   /pdf/0531/R-1978448.pdf.metadata
5735942   05-31-2023 15:19   /pdf/0531/R-1978448.pdf
.......   ....              ....
.......   .....             ....
---------                     -------
2152688064                     1634 files

I also try this but it fail to exclude "metadata" files. The total count exactly the same.

unzip -l 0532.zip | awk '{count = $2} END{print count}'

1634
thichxai
  • 1,073
  • 1
  • 7
  • 16

2 Answers2

1

Just count the number of lines that end with .pdf, using grep -c.

unzip -l 0532.zip | grep -c '\.pdf$'
Barmar
  • 741,623
  • 53
  • 500
  • 612
0

If a line ends with string .pdf increment counter by one and after last line output counter:

unzip -l 0532.zip | awk 'BEGIN{counter=0} /\.pdf$/{counter++} END{print counter}'

Output:

4
Cyrus
  • 84,225
  • 14
  • 89
  • 153