gunzip 预制任务并重新压缩
我想
awk -F, '$1 ~ /F$/' file.dat
在 gzip 压缩文件的整个目录上
执行此操作我希望能够循环遍历每个文件解压缩它执行上述命令(打印出任何结果)重新压缩并移动到下一个压缩文件
如何做到这一点?
谢谢
I want to perform this
awk -F, '$1 ~ /F$/' file.dat
on a whole direcory of gziped files
I want to be able to loop through each file unzip it perform the above command (print out any findings) rezip and move onto the next zipped file
how can this be done?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,如果您必须将所有内容都放在一行中:
那应该适合您
Well if you have to have it all in one line:
That should work for you
在我看来,您想要输出以逗号分隔的字段列表中的第一个字段以“F”结尾的行,
如果您不关心列出这些行来自哪个 .gz 文件,或者其中的哪个文件gzip 压缩的文件 - 也就是说,您只需要列出的行 - 您甚至不必先压缩 .gz 文件,这样您就不必重新压缩它们。
对于当前目录树中的每个文件,使用带有 xargs 的查找。 此示例将其限制为仅当前目录,但只需省略“-maxdepth 1”即可获取整个目录树
这表示查找以“.gz”结尾的文件并用 NUL 终止符写入其名称< /em> (-print0 中的 0),通过 xargs 管道输出,它将根据 NUL 字符(“-0”arg)将列表分开,并在文件上运行 zcat。 通过 awk 命令传输该输出,您将得到写出的相关行。
It looks to me that you want to output lines where the first field, in a comma-separated list of fields, ends with 'F'
If you don't care about listing which .gz file the lines come from, or which file within the gzipped file -- that is, you just want the lines listed -- you don't even have to gunzip the .gz files first, that way you won't have to re-zip them.
For every file in the current directory tree, use a find with xargs. This example limits it to only the current directory, but just leave out the "-maxdepth 1" to get the whole directory tree
This says to find files that end in ".gz" and write their names with a NUL terminator (the 0 in -print0), pipe that output through xargs which will pick the list apart based on NUL chacracters (the "-0" arg) and run zcat on the files. Pipe that output through your awk command and you'll get the relevent lines written out.
一个 shell 脚本怎么样:
只需确保
$1
没有.gz
扩展名。那么你可以这样做:
how about a shell script that does:
Just make sure
$1
doesn't have the.gz
extension.then you can do something like: