我有一个非常大的 zip 文件(~10 GB),我想解压它,结果必须传递给两个命令。两个后续命令的结果必须附加到文件中,并且
目前,我运行
unzip -p bigFile.zip | head -n 1 >> output.txt
unzip -p bigFile.zip | grep -v 'skipLine' >> output.txt
Run Code Online (Sandbox Code Playgroud)
这给出了大约一百万行。现在,我想用 1 行来做。使用tee
,我想出了
unzip -p bigFile.zip | tee >(head -n 1 >> output.txt) >(grep -v 'skipLine'
>> output.txt)
Run Code Online (Sandbox Code Playgroud)
但该output.txt
文件仅包含 51 行,其中最后一行甚至不完整。另外,后一个命令将结果打印到终端,这是我不想要的。
我也尝试过
unzip -p bigFile.zip | tee >(head -n 1 >> output.txt) | grep -v 'skipLine'
>> output.txt
Run Code Online (Sandbox Code Playgroud)
但不幸的是,这也不起作用。
任何帮助是极大的赞赏!没有必要使用tee
,任何其他命令都可以正常工作,只要我可以将部件的输出传递unzip
给head
和grep
命令。
编辑:head
如果和grep
命令的输出可以“组合”然后传递给 ,那就更好了zip
。这可能吗?
您可以解压并通过管道输入 shell 脚本,该脚本使用并打印第一行,并允许 grep 使用其余内容:
unzip -p bigFile.zip | {
IFS= read -r header # consume the first line, verbatim
printf "%s\n" "$header"
grep -v 'skipLine'
} >> output.txt
Run Code Online (Sandbox Code Playgroud)
从块打印的所有内容都会附加到输出文件中。
归档时间: |
|
查看次数: |
2167 次 |
最近记录: |