在压缩文件中计算文件数,但排除扩展名为 .metadata 的文件。

huangapple go评论52阅读模式
英文:

Count files but exclude extention .metadata in the zip file

问题

我可以获取ZIP文件中文件的计数,但无法排除带有元数据扩展名的文件。如何只计算ZIP文件中的“pdf”文件。我非常感谢您能提供的任何帮助。

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

我也尝试了这个方法,但未能排除“metadata”文件。总计数与之前完全相同。

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

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

答案1

得分: 1

只计算以 .pdf 结尾的行数,使用 grep -c

unzip -l 0532.zip | grep -c '\.pdf$'
英文:

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

unzip -l 0532.zip | grep -c '\.pdf$'

答案2

得分: 0

如果一行以字符串.pdf结尾,则将counter增加一,并在最后一行输出counter

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

输出:

4
英文:

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:
<pre>
4
</pre>

huangapple
  • 本文由 发表于 2023年6月1日 03:49:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76376807.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定