对于我在 `ls |grep` 问题中

发布于 2024-09-08 17:30:49 字数 555 浏览 7 评论 0原文

这是我用来解压文件 grep 解压 tar 中文件内容的代码,然后删除解压的文件。我没有足够的空间来一次解压所有文件。

我遇到的问题是 `ls | 中的 f 的 grep -v *.gz 行这应该找到从 tar 中出来的文件,并且可以通过没有 .tar.gz 扩展名来识别,但它似乎没有拾取它们?

任何帮助将不胜

感激

for i in *.tar.gz; 
do echo $i >>outtput1; 
     tar -xvvzf $i; mv $i ./processed/; 
     for f in `ls | grep -v *.gz`;  ----- this is the line that isn't working
     do echo $f  >> outtput1; 
     grep 93149249194 $f >> 
     outtput1; grep 788 $f >> outtput1; 
     rm -f $f; 
     done; 
done

This is the code i'm using to untar a file grep on the contents of the files within the tar and then delete the untared files. I dont have enough space to untar all files at once.

the issue i'm having is with the for f in `ls | grep -v *.gz line this is supposed to find the files that have come out of the tar and can be identified by not having a .tar.gz extension but it doesnt seem to pick them up?

Any help would be much appreciated

M

for i in *.tar.gz; 
do echo $i >>outtput1; 
     tar -xvvzf $i; mv $i ./processed/; 
     for f in `ls | grep -v *.gz`;  ----- this is the line that isn't working
     do echo $f  >> outtput1; 
     grep 93149249194 $f >> 
     outtput1; grep 788 $f >> outtput1; 
     rm -f $f; 
     done; 
done

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

抚笙 2024-09-15 17:30:50

尝试 ls -1 | grep -v“\\.gz$”。 -1 将使 ls 每行输出一个结果。我还通过几种方式为您修复了正则表达式。

尽管解决整个问题的更好方法是使用 find -exec

Try ls -1 | grep -v "\\.gz$". The -1 will make ls output one result per line. I've also fixed your regex for you in a few ways.

Although a better way to solve this whole thing is with find -exec.

洛阳烟雨空心柳 2024-09-15 17:30:50

将其更改为 ls | grep -v "*.gz",您必须引用 *.gz,否则它只会 glob 工作目录中的文件并 grep 它们。

Change it to ls | grep -v "*.gz", you have to quote *.gz because otherwise it will just glob the files in the working directory and grep them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文