对于我在 `ls |grep` 问题中
这是我用来解压文件 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试 ls -1 | grep -v“\\.gz$”。
-1
将使ls
每行输出一个结果。我还通过几种方式为您修复了正则表达式。尽管解决整个问题的更好方法是使用
find -exec
。Try
ls -1 | grep -v "\\.gz$"
. The-1
will makels
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
.将其更改为 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.