LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Awk on multiple .gz files (https://www.linuxquestions.org/questions/programming-9/awk-on-multiple-gz-files-870086/)

BarataPT 03-21-2011 05:33 PM

Awk on multiple .gz files
 
Hi all,

Hi have a dir with 6 sub-dirs that have about 165 .txt.gz files.

What i want to do is to print from the last blank line until eof.

I can do it for one file, but can't figure it out for multiple files. For one file i do this way:

Quote:

zcat file.txt.gz | tac | awk '{ if ($0 ~ /^$/) exit; else print $0}'
For multiple files i have to use "find . -type f | xargs zcat", and i don't know how to do that for each file found.

BarataPT 03-21-2011 06:00 PM

I got it.

Quote:

for i in `find . -type f`; do zcat "$i" | tac | awk '{ if ($0 ~ /^$/) {printf "\n"; exit} else print $0}'; done

grail 03-21-2011 08:43 PM

Be cautious of using for loop as if file names contain spaces it will fail.

Also you could remove tac and using a more simple awk like:
Code:

zcat "$i" | awk 'END{print}' RS=""

BarataPT 03-22-2011 05:13 AM

Thanks for the tips ;)


All times are GMT -5. The time now is 11:13 AM.