awk pattern matching and shell issue.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk pattern matching and shell issue.
# 1  
Old 12-22-2011
Java awk pattern matching and shell issue.

Please help me in this issue.
I am unable to get the job,seems the awk not browsing the files.
Please find my tries below.

I have attached two files :
1.tobesearched.txt - a glimpse of a huge log file.
2.searchstring.txt - searching keys.

these are the two scripts i tried writing:

This is the shell script:
Code:
#!/bin/ksh
file="/new_var_app/temp/restoredlogs/cclogger/modified_RRN"
while read line
do
awk -f abc.awk cclogger.Z.2011-11-30_00:00:01 $line 
done <$file

This is the awk script abc.awk:
Code:
#!/bin/awk -f 
BEGIN {
{flag=1}
{
newstring=sprintf("%s %s %s %s %s %s %s %s %s %s %s %s",ARGV[2],ARGV[3],ARGV[4],ARGV[5],ARGV[6],ARGV[7],ARGV[8],ARGV[9],ARGV[10],ARGV[11],ARGV[12],ARGV[13])
print "Arg1--->"ARGV[1]
print newstring
if($0 ~ /$newstring/)
{flag=0}
if(flag == 0)
{ print $0 }
if ($0 ~ /dumpMsg/)
{
if (flag == 0)
{
flag=1
}
}
}
} 

Here I am trying to take the searchstrings from the file searchstring.txt
and trying to search in the big log file.

My objective is : if i find a match,I have to paste the pattern

The pattern should
start with the line containing the search string.
it ends when it finds the keyword "dumpMsg".

Last edited by Franklin52; 12-22-2011 at 03:22 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 12-22-2011
Code:
 
fgrep -f searchstring.txt tobesearched.txt | grep "dumpMsg$"

# 3  
Old 12-22-2011
Unexpected output ..Scenario explained clearly

Hi tkam,
It is not giving the desired output.
Smilie
Let me explain what I want :
Suppose this is the logfile:
Code:
This is George
He is a good guy
He loves burger
End
I love Britain
This is Raz
He is a Bad guy
He drinks a lot
End
I love Nederlands
This is Tommy
He is a singer
He cooks pasta
End
I love Mexico

The file with search strings are:
Code:
George
Tommy

The output should be like this:
Code:
This is George
He is a good guy
He loves burger
End
This is Tommy
He is a singer
He cooks pasta
End

Moderator's Comments:
Mod Comment How to use code tags

Last edited by Franklin52; 12-22-2011 at 03:23 AM.. Reason: Please use code tags for code and data samples, thank you
# 4  
Old 12-22-2011
Code:
$ while read pattern; do perl -lane "print if /$pattern/ .. /End/" file.txt; done < search.txt  

This is George
He is a good guy
He loves burger
End
This is Tommy
He is a singer
He cooks pasta
End

# 5  
Old 12-22-2011
Hi tkamraj,
Code:
[host:Server]{testapp}/new_var_app/netx=>abc.sh > output.txt
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LC_ALL = (unset),
        LC__FASTMSG = "true",
        LANG = "En_US"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").


Getting the below error.
Output is written only for the first search string ... Smilie

There are 400+ search string.

Last edited by Franklin52; 12-22-2011 at 03:24 AM.. Reason: Please use code tags for code and data samples, thank you
# 6  
Old 12-22-2011
show your original file and the search string file

---------- Post updated at 12:46 PM ---------- Previous update was at 12:45 PM ----------

also, post the command, which u tried
# 7  
Old 12-22-2011
Attached the screenshot of the two files.

Hi tkamaraj,

Find the attached screenshots for the two files..

The log file is very big with repeating patterns.

the command i gave :

while read pattern; do perl -lane "print if /$pattern/ .. /dumpMsg/" cclogger.Z.2011-11-30_00:00:01; done < modified_RRN
awk pattern matching and shell issue.-searchstringjpg
awk pattern matching and shell issue.-filetobesearchedjpg

Last edited by deboprio; 12-22-2011 at 03:39 AM.. Reason: to post the command i tried
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Big pattern file matching within another pattern file in awk or shell

Hi I need to do a patten match between files . I am new to shell scripting and have come up with this so far. It take 50 seconds to process files of 2mb size . I need to tune this code as file size will be around 50mb and need to save time. Main issue is that I need to search the pattern from... (2 Replies)
Discussion started by: nitin_daharwal
2 Replies

2. Shell Programming and Scripting

awk script issue redirecting to multiple files after matching pattern

Hi All I am having one awk and sed requirement for the below problem. I tried multiple options in my sed or awk and right output is not coming out. Problem Description ############################################################### I am having a big file say file having repeated... (4 Replies)
Discussion started by: kshitij
4 Replies

3. Shell Programming and Scripting

awk pattern matching

can somebody provide me with some ksh code that will return true if my the contents in my variable match anyone of these strings ORA|ERROR|SP2 variable="Error:ORA-01017: Invalid username/password; logon denied\nSP2-0640:Not connected" I tried this and it does not seem to work for me ... (3 Replies)
Discussion started by: BeefStu
3 Replies

4. Shell Programming and Scripting

issue with pattern matching

i have 2 strings with values below which are read from a file 1 ---> end 2 ---> string(1)newline="\n"; which need to be compared inside an if block as below if \\n\"\;" ] then echo "pattern match" fi but the above code is not working (1 Reply)
Discussion started by: cvsanthosh
1 Replies

5. UNIX for Dummies Questions & Answers

awk - pattern matching?

Hello all, I am trying to sort thru a database and print all the customers whose first names are only four characters. I just want to pull the first name only from the database. the database records appear like this in file: Mike Harrington:(510) 548-1278:250:100:175; first is name Mike... (4 Replies)
Discussion started by: citizencro
4 Replies

6. Shell Programming and Scripting

Pattern matching in Perl issue

Hello all, I have written a perl script which searched for a file in a folder, and return the value found or not found. The file that we are getting is a weekly file and everyweek, the date changes. So for this i have written a file pattern matching script, but i am not getting the... (4 Replies)
Discussion started by: msrahman
4 Replies

7. Shell Programming and Scripting

AWK pattern matching

Hi, How can I tell awk to print all lines/columns if column number 5 contains the word Monday? I have tried nawk -F, '$5==Monday' OFS=, myfile > outputfile but that doesn't work (I am a newb!!) Thanks, (7 Replies)
Discussion started by: keenboy100
7 Replies

8. Shell Programming and Scripting

pattern matching using awk.

Dear Team, How do we match two patterns on the same line using awk?Are there any logical operators which i could use in awk like awk '\gokul && chennai\' <filename> Eg: Input file: gokul,10/11/1986,coimbatore. gokul,10/11/1986,bangalore. gokul,12/04/2008,chennai.... (2 Replies)
Discussion started by: gokulj
2 Replies

9. Shell Programming and Scripting

Issue with Pattern Matching in Unix

Hi, I am trying to replace a specific column values in a csv file with double quotes. Example: SNO,NAME,ZIPCODE,RANK,CARE_OF 1,Robert,74538,12,RICHARD JOHNSON, P.C 2,Sam,07564,13,% R.S MIKE, V.K.S 3,Kim, Ed,12345,14,@90 KMS, %TK Desired Output: SNO,NAME,ZIPCODE,RANK,CARE_OF... (1 Reply)
Discussion started by: techmoris
1 Replies

10. Shell Programming and Scripting

AWK pattern matching, first and last

In a nutshell, I need to work out how to return the last matching pattern from an awk //,// search. I can bring back the first, but am unsure how to obtain the last, and a simple tail won't work as the match could be over multiple lines. Secondly I would like some way of pattern matching, a... (10 Replies)
Discussion started by: smb_uk
10 Replies
Login or Register to Ask a Question