Sponsored Content
Top Forums Shell Programming and Scripting Sed/awk gods, I need your Help! Fancy log extraction Post 302123038 by aigles on Friday 22nd of June 2007 03:00:13 PM
Old 06-22-2007
Try the foolowing script (named th.sh):

Code:
awk -v Id=123456 -v FS='[][]' '
   $7 ~ "BEGIN REQUEST sessionID=" Id {
      thread = $4;
   }
   $4 == thread
   $7 ~/END REQUEST/ { thread="" }
' th.txt

Inputfile (th.txt):
Code:
[2007-06-22 09:33:15,840][thread-1][BEG_]BEGIN REQUEST sessionID=100001
[2007-06-22 09:33:15,843][thread-1][BEG_]BEGIN REQUEST sessionID=123456
[2007-06-22 09:33:15,844][thread-1][DEB_]boatload of lines for thread-1 detailing the whereabouts of the customer
[2007-06-22 09:33:15,844][thread-2][DEB_]Here is activity from another customer - we don't need that
[2007-06-22 09:33:15,844][thread-1][DEB_]boatload of lines for thread-1 detailing the whereabouts of the customer
[2007-06-22 09:33:15,844][thread-3][DEB_]more activity from yet another customer- we don't need that
[2007-06-22 09:33:15,844][thread-1][DEB_]boatload of lines for thread-1 detailing the whereabouts of the customer
[2007-06-22 09:33:15,843][thread-1][BEG_]END REQUEST
[2007-06-22 09:33:15,843][thread-34][BEG_]BEGIN REQUEST sessionID=34444
[2007-06-22 09:33:15,844][thread-1][DEB_]Another customer took thread-1! We don't want that log entry either
[2007-06-22 09:33:15,844][thread-34][DEB_]yet more activity from the customer but under a different thread!
[2007-06-22 09:33:15,843][thread-34][BEG_]END REQUEST

Output:
Code:
[2007-06-22 09:33:15,843][thread-1][BEG_]BEGIN REQUEST sessionID=123456
[2007-06-22 09:33:15,844][thread-1][DEB_]boatload of lines for thread-1 detailing the whereabouts of the customer
[2007-06-22 09:33:15,844][thread-1][DEB_]boatload of lines for thread-1 detailing the whereabouts of the customer
[2007-06-22 09:33:15,844][thread-1][DEB_]boatload of lines for thread-1 detailing the whereabouts of the customer
[2007-06-22 09:33:15,843][thread-1][BEG_]END REQUEST


Last edited by aigles; 06-22-2007 at 04:35 PM.. Reason: typo error, remove $ from Id assignment
 

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SED scipt help - line extraction

Forgive me if this is a dumb question...I'm a Windows sys admin with little programming knowledge. I have files containing anywhere from 3 to 200 lines. Using SED, I want to extract only lines containing a specific instance of "ISS." It is possible that "ISS" will occur several times in a... (10 Replies)
Discussion started by: thuston22
10 Replies

2. Shell Programming and Scripting

extraction of samba shares with sed

Hi there, My samba configuration file looks like that : ... ... path = /home/samba/profiles/ ... path = /home/samba/shares/family valid users = family path = /home/samba/shares/admins valid users = admins path = /home/samba/shares/publicI want to extract the list of standard... (3 Replies)
Discussion started by: chebarbudo
3 Replies

3. Shell Programming and Scripting

Extraction of text using sed or awk command

Hi All, I need to extract 543 from the command below : # pvscan PV /dev/sdb1 VG vg0 lvm2 Total: 1 543.88 GB] / in use: 1 / in no VG: 0 I have the following command which does the job, but I think this could be achieved in a more simple way using sed or awk. Any help is... (7 Replies)
Discussion started by: nua7
7 Replies

4. Shell Programming and Scripting

Obscure sed extraction syntax

Hi, Could anyone clearly explain me the below sed construct in detail to get to know what it actually does? sed 's/\(* *\)//4' echo 'test;10;20' | sed 's/*;\(*\)/\1/' (1 Reply)
Discussion started by: royalibrahim
1 Replies

5. UNIX for Dummies Questions & Answers

awk/sed match and extraction

Hi, I have a file like this- aa 12 23 34 aa 21 34 56 aa 78 45 56 I want to print out only the lines after the last aa. How do I do this? I tried using grep -A and sed -n, but both didnt work as I wanted to. Could someone help me out please.. (3 Replies)
Discussion started by: jamie_123
3 Replies

6. Shell Programming and Scripting

sed text extraction between 2 patterns using variables

Hi everyone! I'm writting a function in .bashrc to extract some text from a file. The file looks like this: " random text Begin CG step 1 random text Begin CG step 2 ... Begin CG step 100 random text" For a given number, let's say 70, I want all the text between "Begin CG... (4 Replies)
Discussion started by: radudownload
4 Replies

7. Shell Programming and Scripting

Extraction problem with sed command

Hi All I am trying to remove the line having specific pattern from a file by using sed command I have the file named ODS_REP_SRCE_File.txt with content as: ... (1 Reply)
Discussion started by: Shilpi Gupta
1 Replies
xchklog(8)						JFS utility - extract fsck.jfs log						xchklog(8)

NAME
xchklog - extract a log from the JFS fsck workspace into a file SYNOPSIS
xchklog [ -f output.file ] [ -p ] [ -V ] device DESCRIPTION
xchklog extracts the contents of either the most recent or immediately prior JFS fsck service log from the specified device, and writes the output into a specified or default file. (The default file name is <pwd>fscklog.new. If the -p option is used, the default file name is <pwd>fscklog.old.) The contents of the output file can be formatted into text by using the JFS utility xchkdmp. device is the special file name corresponding to the actual device from which the fsck log will be extracted (e.g. /dev/hdb1 ). OPTIONS
-f output.file Specify the output file name, overriding the default file name. output.file must be 127 characters or less in length. output.file will be created in the present working directory unless it is fully qualified. -p Extract the prior log (as opposed to the most recent log). -V Print version information and exit (regardless of any other chosen options). EXAMPLES
Extract the most recent log on /dev/hda5 into <pwd>fscklog.new: xchklog /dev/hda5 Extract the most recent log on /dev/hdb3 into /temp/l9651107.log: xchklog -f /temp/l9651107.log /dev/hdb3 Extract the prior log on /dev/hdb4 into <pwd>fscklog.old: xchklog -p /dev/hdb4 REPORTING BUGS
If you find a bug in JFS or xchklog, please report it via the bug tracking system ("Report Bugs" section) of the JFS project web site: http://oss.software.ibm.com/jfs Please send as much pertinent information as possible, including any xchklog error messages and the complete output of running fsck.jfs with the -v option on the JFS device. SEE ALSO
xchkdmp(8), mkfs.jfs(8), fsck.jfs(8), logdump(8), logredo(8), xpeek(8) AUTHOR
Barry Arndt (barndt@us.ibm.com) xchklog is maintained by IBM. See the JFS project web site for more details: http://oss.software.ibm.com/jfs January 11, 2002 xchklog(8)
All times are GMT -4. The time now is 03:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy