LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-21-2011, 06:33 PM   #1
BarataPT
LQ Newbie
 
Registered: Mar 2011
Posts: 12

Rep: Reputation: 1
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.
 
Old 03-21-2011, 07:00 PM   #2
BarataPT
LQ Newbie
 
Registered: Mar 2011
Posts: 12

Original Poster
Rep: Reputation: 1
I got it.

Quote:
for i in `find . -type f`; do zcat "$i" | tac | awk '{ if ($0 ~ /^$/) {printf "\n"; exit} else print $0}'; done
 
1 members found this post helpful.
Old 03-21-2011, 09:43 PM   #3
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,631

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
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=""
 
Old 03-22-2011, 06:13 AM   #4
BarataPT
LQ Newbie
 
Registered: Mar 2011
Posts: 12

Original Poster
Rep: Reputation: 1
Thanks for the tips
 
  


Reply

Tags
awk, loop, tac, zcat


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
extracting columns from multiple files with awk orcaja Linux - Newbie 7 02-14-2012 11:24 PM
How to split a file into multiple files using AWK? keenboy Linux - General 1 08-05-2010 02:18 PM
[SOLVED] AWK Multiple Passes MTK358 Programming 14 03-13-2010 02:03 AM
[SOLVED] split multi line record into multiple files with awk pcock Programming 10 11-12-2009 05:12 AM
AWK/SED Multiple pattern matching over multiple lines issue GigerMalmensteen Programming 15 12-03-2006 06:08 PM


All times are GMT -5. The time now is 07:39 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration