Reputation: 1197
I want to output a specific line of several compressed files. Due to my research I think I have to extract the file and afterwards grep my strings. E.g. gunzip -c
just outputs to STDOUT
where I can further process.
I tried:
find path/to/files -name archive.gz | xargs gunzip -c | awk 'NR==100{print}'
which just outputs one string (the one from the second file). Without the xargs
I am getting the error: gzip: stdin: not in gzip format
If there actually is an option for grep, sed, awk, perl, or any other standard bash tool, I would be pleased to get informed.
Upvotes: 1
Views: 122
Reputation: 123508
You need the -exec
option in order to issue a shell command:
find path/to/files -name archive.gz -exec sh -c "gzip -dc {} | awk 'NR==100'" \;
This would execute the command for every output generated by the find
command.
Upvotes: 2