Think about it for a moment.
- You tell the shell that your entire pipeline should be considered failed if any component fails.
- You say
zcatwrite your conclusion to head. - Then you say
headexit after reading 12 lines from the input stream, which is longer than 12 lines.
, : zcat , ! , - , - - .
zcat , zcat , , , , . .
, zcat , EPIPE, EPIPE write : , - .
head ( FIFO) , EPIPE, . zcat zcat , , , , .
- , , , , - :
var=$(head -n 12 < <(zcat file.gz))
zcat , . ( , $var 12 , /).
Python gzip. Python ( Python 2 3.x), , :
zhead_py=$(cat <<'EOF'
import sys, gzip
gzf = gzip.GzipFile(sys.argv[1], 'rb')
outFile = sys.stdout.buffer if hasattr(sys.stdout, 'buffer') else sys.stdout
numLines = 0
maxLines = int(sys.argv[2])
for line in gzf:
if numLines >= maxLines:
sys.exit(0)
outFile.write(line)
numLines += 1
EOF
)
zhead() { python -c "$zhead_py" "$@"; }
... zhead, , , - . ( zhead in.gz 5, 5 in.gz).