![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| using grep and print filename | ahjiefreak | Shell Programming and Scripting | 5 | 01-10-2008 11:47 AM |
| grep string and output filename | happyv | Shell Programming and Scripting | 3 | 11-20-2007 12:16 AM |
| Get Filename and Line Number using grep | ceemh3 | UNIX for Dummies Questions & Answers | 4 | 09-17-2007 10:35 AM |
| Grep all files matching partial filename | mharley | Shell Programming and Scripting | 3 | 06-08-2005 02:17 PM |
| Losing filename in grep output | netguy | Shell Programming and Scripting | 6 | 04-27-2004 11:39 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
grep and awk showing filename in loop
I am attempting to grep a list of files for a string an and then only extract the 3rd and 4th field of from the line. That's easy. But I want to prefix the line with the filename that the information came from.
for filename in `ls -1 *.txt' do grep search_text $filename | awk '{print $3" "$4}' done This displays the 3rd and 4th field of all lines in the list of files as in: Field3 Field4 Field3 Field4 but I would like to see a.txt Field3 Field4 b.txt Field3 Field4 Can somone give me a clue on how to do this. Thanks, Scott f |
|
||||
|
Thanks...this got me on the right track but I left something out that causes this solution to have a problem. The files are am searching through are gzipped. When I try to gunzip the file and pipe the data to awk, awk now things the FILENAME is standard in. Any thoughts?
for filename in `ls -1 *.txt.gz` do { gunzip < $filename 2>>/dev/null; echo $?>>rc.txt; } | awk '/search_text/ {print $3,$4}' done |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|