如何获取所有压缩文件的前 10 行?
How can I get the 10 first lines of all my compressed files?
我有一堆 M
文件,我想从中提取前 N
行(来自 each)。我的文件在 BZ2 中压缩。否则,做head -10 *
就够了。
例如:假设我想从我的所有文件中提取前两行(A.txt、B.txt、C.txt)。
A.txt:
1A
2A
3A
4A
B.txt:
1B
C.txt:
1C
2C
预期的结果应该是这样的(即包含这些行,而不是强制按顺序排列):
1A
2A
1B
1C
2C
我尝试了以下方法:
bzcat * | head -10
给我整个解压文件的 前 10 行 ,即没有足够的输出。我这里只有 1A 2A
。
bzcat | head -10 *
给我每个 压缩的 文件的前 10 行,即无法阅读。
有人知道吗?
使用 for
循环:
for i in *; do bzcat "$i" | head -n10; done
或find
:
find -type f -exec bash -c 'bzcat | head -n10' _ {} \;
使用xargs:
find . -name "*" | xargs -I {} sh -c "bzcat {} | head -n10"
xargs -I 替换-str :
Replace occurrences of replace-str in the initial-arguments
with names read from standard input. Also, unquoted blanks do
not terminate input items; instead the separator is the
newline character.
我有一堆 M
文件,我想从中提取前 N
行(来自 each)。我的文件在 BZ2 中压缩。否则,做head -10 *
就够了。
例如:假设我想从我的所有文件中提取前两行(A.txt、B.txt、C.txt)。
A.txt:
1A
2A
3A
4A
B.txt:
1B
C.txt:
1C
2C
预期的结果应该是这样的(即包含这些行,而不是强制按顺序排列):
1A
2A
1B
1C
2C
我尝试了以下方法:
bzcat * | head -10
给我整个解压文件的 前 10 行 ,即没有足够的输出。我这里只有1A 2A
。bzcat | head -10 *
给我每个 压缩的 文件的前 10 行,即无法阅读。
有人知道吗?
使用 for
循环:
for i in *; do bzcat "$i" | head -n10; done
或find
:
find -type f -exec bash -c 'bzcat | head -n10' _ {} \;
使用xargs:
find . -name "*" | xargs -I {} sh -c "bzcat {} | head -n10"
xargs -I 替换-str :
Replace occurrences of replace-str in the initial-arguments with names read from standard input. Also, unquoted blanks do not terminate input items; instead the separator is the newline character.