简体   繁体   English

如何在不解压的情况下找到tar文件中文件的行数

[英]How to find the number of lines of the files inside a tar file without extracting

I have a tar file, which has lots of csv files in it. 我有一个tar文件,其中有很多csv文件。 Is there a way to find the number of lines in each csv file without extracting it in linux? 有没有一种方法可以找到每个csv文件中的行数,而无需在linux中提取它?

I tried 我试过了

for file in $(tar -tf "$tarfile")
do
  NL=`wc -l < "$file"`
done

But it gives error: "No such file or directory". 但是它给出了错误:“没有这样的文件或目录”。

Can anyone help please. 谁能帮忙。

Try this: 尝试这个:

for file in $(tar -tf "$tarfile")
do
    NL=$(tar Oxf "$tarfile" "$file" | wc -l)
done

Oxf extracts the specified file to stdout. Oxf将指定的文件提取到stdout。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从tar文件中的csv文件中提取前几行而不在Linux中提取它? - How to extract first few lines from a csv file inside a tar file without extracting it in linux? Linux - 如何在不提取内容并再次应用 tar 的情况下重命名 .tgz 文件中的文件? - Linux - how to rename files within a .tgz file without extracting contents and applying tar again? 如何在不包含tar文件整个路径的情况下对多个文件进行tar - How to tar several files without containing their whole path in tar file 如何在不提取内容的情况下重命名.tar.gz文件并在UBUNTU中创建新的.tar.gz文件? - How to rename .tar.gz file without extracting the contents and creating the new .tar.gz file in UBUNTU? 打印 tar.gz 中每个文件的第一行而不提取 - Print the first line of each file inside a tar.gz without extracting Docker 没有解压.tar.gz 并且在镜像中找不到文件 - Docker not extracting .tar.gz and cannot find the file in the image 从tar文件中提取特定目录而不创建包含层次结构 - extracting specific dir from tar file without creating the containing hierarchy 在使用tar提取文件时,如何在通配符上使用OR运算符 - How to use OR operator with wildcards while extracting files with tar 如何在bash中没有内部文件夹路径的情况下将特定文件tar到特定文件夹? - How to tar specific files to specific folder without inside folders path in bash? 如何将多个 tar 文件合并为一个 tar 文件 - How to combine multiple tar files into a single tar file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM