Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

awk pattern match by looping through search patterns

Shell Programming and Scripting


Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 07-12-2017   -   Original Discussion by ananan
ananan ananan is offline
Registered User
 
Join Date: Jun 2017
Last Activity: 12 July 2017, 2:38 AM EDT
Posts: 22
Thanks: 5
Thanked 0 Times in 0 Posts
awk pattern match by looping through search patterns

Hi
I am using Solaris 5.10 & ksh

Wanted to loop through a pattern file by reading it and passing it to the awk to match that value present in column 1 of rawdata.txt , if so print column 1 & 2 in to Avlblpatterns.txt. Using the following code but it seems some mistakes and it is running for more time and repeatedly printing the matching pattern.. I think like Cartesian loop. Please correct me where I am wrong. Input pattern 1000 lines and data file will be containing 20000 records.

Code:
 
while read line

do

 awk -F"," '{

 if ( $1 == "'$line'" ){print $1,$2}

}' rawdata.txt >> Avlblpatterns.txt

 done < searchpat.txt

---------- Post updated at 11:43 AM ---------- Previous update was at 11:36 AM ----------

Not shared sample files. Please use your own
Sponsored Links
    #2  
Old Unix and Linux 07-12-2017   -   Original Discussion by ananan
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 17 November 2017, 6:42 AM EST
Location: Aachen, Germany
Posts: 11,616
Thanks: 320
Thanked 3,615 Times in 3,320 Posts
Quote:
Originally Posted by ananan View Post
.
.
.
---------- Post updated at 11:43 AM ---------- Previous update was at 11:36 AM ----------

Not shared sample files. Please use your own
And how would you like you tea served, Sir?


Running awk a thousand times is far from being efficient. If you skim through these fora, you'll find many posts dealing with (and solving) exactly your or very similar problems.
The Following User Says Thank You to RudiC For This Useful Post:
RavinderSingh13 (07-12-2017)
Sponsored Links
    #3  
Old Unix and Linux 07-12-2017   -   Original Discussion by ananan
rbatte1 rbatte1 is offline Forum Staff  
Root armed
 
Join Date: Jun 2007
Last Activity: 17 November 2017, 12:53 PM EST
Location: Lancashire, UK
Posts: 3,365
Thanks: 1,453
Thanked 665 Times in 598 Posts
Although I agree that there are plenty of solutions already on the board, does your file searchpat.txt have a blank line in it or some other line that will match multiple lines?

Perhaps you can better manage your requirement with a grep and a cut. Look at the -f flag in the grep manual page to see if that helps.



Robin
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Egrep patterns in a file and limit number of matches to print for each pattern match ananan Shell Programming and Scripting 10 06-13-2017 02:09 AM
Awk to match a pattern and perform a search after the first pattern RickCharles Shell Programming and Scripting 8 09-07-2012 12:21 AM
Need one liner to search pattern and print everything expect 6 lines from where pattern match made chidori Shell Programming and Scripting 8 03-15-2012 12:46 PM
Perl: Match a line with multiple search patterns Juha Shell Programming and Scripting 10 04-09-2008 02:43 AM
List files that do not match the search pattern olapxpert UNIX for Dummies Questions & Answers 7 04-14-2005 04:49 PM



All times are GMT -4. The time now is 04:29 AM.