The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-31-2006
ucbus ucbus is offline
Registered User
  
 

Join Date: May 2006
Posts: 7
AWK question

I have file "A" containing keywords as sequential records. For each key word in file "A",
1. need to find the files hat contained the keyword in a given directory
2. Find the file name that contained the first occurance of the keyword
3. Print the record that contatined the first occurance of the keyword

I could do this through in-line awk script
if [ $MyTest = 1 ]
then
{ while read str; do
string=$str
let ctr=ctr+1

awk '/'"$string"'/ {print;exit}' /mydir/* >> $outfile

done } < $file

However, this gives error " parameter too long" error if the there are several files. One suggestion was to run the script from separate file
1. Can some one suggest how the above can be put into separate file?
2. Also is it "awk" limitation that I am getting the error "parameter too long" when running from in-line?
Thanks
  #2 (permalink)  
Old 08-01-2006
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,433

Code:
awk '/'"$string"'/ {print;exit}' /mydir/* >> $outfile

The limitations comes from the shell and not from awk.
The sheel replace /mydir/* by the list of files matching, so the command line can be greatear than the max limit.
A possible solution :

Code:
cd /mydir
ls -1 | xargs awk '/'"$string"'/ {print;exit}' >>$outfile
cd -

Jean-Pierre.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:35 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0