Need help in retrieving log from a UNIX file using the search patterns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help in retrieving log from a UNIX file using the search patterns
# 1  
Old 01-06-2011
Need help in retrieving log from a UNIX file using the search patterns

Hi everyone,

I am trying to retrieve certain log from a big file. The log size can be from 200 - 600 lines. I have 3 search patterns, out of which 2 (first and last lines) search patterns are common for all the transactions but 3rd search pattern (occurs in the middle of transaction) is unique.

Now, using these three search patterns, I want to retreive the complete transaction log (start to end) into a seperate file.

I think, this can be done using awk. I know the basic awk commands but not comfortable with the awk programming.

Can anyone help me on this? Thanks in advance.
# 2  
Old 01-06-2011
Problem is not much clear. Please post a sample input, show all three patterns and expected output.
# 3  
Old 01-06-2011
Thanks Anurag for the quick response. Unfortunately I can't post sample input but here is the scenario

Starting line (for tx - 1)
Transaction ID (Unique for each transaction)
End line (for tx -1)
starting line (for tx -2)
Transaction ID
End line (for tx -2)
.....
.....
starting line (for tx -10)
Transaction ID
End line (for tx -10)

The start/end lines are common for all the transactions. The transaction ID is present as part of the line in the middle of the respective transaction log.

Now, I have to write a script so that it can pull the requested transaction log (from starting line to end line) by searching the transaction ID from the log into a seperate file.
# 4  
Old 01-06-2011
"by searching the transaction ID" ??
How you need to search log for a transaction ID.
Do you need log for only one transaction ID while one run? OR more.
Say if you want to seach for transaction ID 100 and 200, then Do you want following output:
Code:
starting line (for tx -2)
100
End line (for tx -2)
starting line (for tx -3)
200 
End line (for tx -3)

Please explain completely. You told only input file format. But not explained how do you plan to pass transaction ID you need to search.
# 5  
Old 01-06-2011
One way of tacking this task. First find the line number of the match on "Transaction ID" then pass through the original file looking for the lines before, equal, and after the the match.

Code:
mylogfilename="/path/mybiglogfilename"

TAB="`echo \0011`"      # Tab character
mytransaction_id="000000000000000"
cat -n "${mylogfilename}" | grep "${mytransaction_id}" | awk '{print $1,$2}'| while read mylineno mydata
do
      mylineno_before=`expr ${mylineno} - 1`
      mylineno_after=`expr ${mylineno} + 1`
      sed -n "${mylineno_before},${mylineno_after} p" ${mylogfilename}
done

# 6  
Old 01-20-2011
Thanks Methyl. I will try this solution and get back to you guyz as soon as I am done.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk search patterns from file in another

I would like to grep for aaa and bbb and ccc from one line in file1.txt in any order on a line on file2.txt file1.txt aaa bbb ccc ddd fff ggg hhh ddd jjj jjj cccfile2.txt aaa bbb ccc ddd fff ggg --> output whole line since it matches with aaa bbb ccc of file1.txt aaa ddd jjj hhh --> no... (1 Reply)
Discussion started by: sdf
1 Replies

2. Shell Programming and Scripting

Retrieving the relevant search from search file in the main file

I have two files: file 1: hello.com neo.com,japan.com,example.com news.net xyz.com, telecom.net, highlands.net, software.com example2.com earth.net, abc.gov.uk file 2: neo.com example.com abc.gov.uk file 2 are the search keys to search in file 1 if any of the search... (7 Replies)
Discussion started by: csim_mohan
7 Replies

3. Shell Programming and Scripting

How to search 2 separate patterns from a 2nd file.?

Hi Guys, Need your urgent support please. I have a file with 3 separate strings separated by a comma and 2nd file which has a sentence where I can find these 3 strings. I need to find sentences which do not have these strings and maybe redirect it to a 3rd file. All the 3 strings will occur... (3 Replies)
Discussion started by: danish0909
3 Replies

4. Shell Programming and Scripting

How to search multiple patterns and remove lines from a file?

Hi, I have a file content as below. Table : PAYR Displayed fields: 15 of 15 Fixed columns: 4 List width 0999... (4 Replies)
Discussion started by: shirdi
4 Replies

5. Shell Programming and Scripting

How to search Multiple patterns in unix

Hi, I tried to search multiple pattern using awk trans=1234 reason=LN MISMATCH rec=`awk '/$trans/ && /'"$reason"'/' file` whenevr i tried to run on command promt it is executing but when i tried to implment same logic in shell script,it is failing i.e $rec is empty ... (6 Replies)
Discussion started by: ns64110
6 Replies

6. Shell Programming and Scripting

reading lines from a file between two search patterns

Hi, I am new to shell scripting and is working on a script to extract lines from a log file between two time stamps using awk command. After some research I used following command: awk '/01 Oct 2011/{p=1} /10 Oct 2011/{p=0} p' test.log >> tmp.log This works fine. But now i want to... (3 Replies)
Discussion started by: davidtd
3 Replies

7. Shell Programming and Scripting

to read two files, search for patterns and store the output in third file

hello i have two files temp.txt and temp_unique.text the second file consists the unique fields from the temp.txt file the strings stored are in the following form 4,4 17,12 15,65 4,4 14,41 15,65 65,89 1254,1298i'm able to run the following script to get the total count of a... (3 Replies)
Discussion started by: vaibhavkorde
3 Replies

8. Shell Programming and Scripting

Retrieving values from tab-delimited file in unix script

Hi I am trying to retrieve values from a tab-delimited file.I am using while read record value=`echo $record | cut -f12` done Where 12 is the column no i want retieve and record is one line of the file. But it is returning the full record. Plz help (4 Replies)
Discussion started by: akashtcs
4 Replies

9. Shell Programming and Scripting

Perl - How to search a text file with multiple patterns?

Good day, great gurus, I'm new to Perl, and programming in general. I'm trying to retrieve a column of data from my text file which spans a non-specific number of lines. So I did a regexp that will pick out the columns. However,my pattern would vary. I tried using a foreach loop unsuccessfully.... (2 Replies)
Discussion started by: Sp3ck
2 Replies

10. UNIX for Dummies Questions & Answers

How to parameterize multiple search patterns and generate a new file

I have one file: 123*100*abcd*10 123*101*abcd*-29*def 123*100*abcd*-10 123*102*abcd*-105*asd I would like to parameterize the search patterns in the following way so that the user could dynamically change the search pattern. *100* and *- (ie *minus) *102* and *- The output that is... (6 Replies)
Discussion started by: augustinep
6 Replies
Login or Register to Ask a Question