Sed/awk gods, I need your Help! Fancy log extraction


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sed/awk gods, I need your Help! Fancy log extraction
# 8  
Old 06-22-2007
Quote:
Originally Posted by aigles
I have fixed a typo error, remove the $ from the Id variable asignment :
Code:
awk -v Id=123456 -v FS='[][]' '

Aigles, you're my hero! It works perfectly.

Would it be too much to ask for you to explain what exactly the script tells awk to do? I'd like to understand how this works, to improve myself and be able to use this in other contexts.

Thanks a lot!
# 9  
Old 06-22-2007
awk -v Id=$123456 -v FS='[][]' '
. . .
' th.txt


Run awk with file th.txt for input.
Two variables are define :
Id : sessionId to extract
FS : input Field Separator. The two characters [ and ] acts as field separator.
In that case the thread id is field $4 and the text part is field $7.

$7 ~ "BEGIN REQUEST sessionID=" Id {
thread = $4;
}


If the text part (field $7) contains 'BEGIN REQUEST' for the required sessionId,
the thread (field $4) is memorized into the variable thread.

$4 == thread

All the lines with the memorized thread are selected and printed.

$7 ~/END REQUEST/ { thread="" }


When END REQUEST is found, the value of the thread is reseted.
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

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. 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

6. 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

7. 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
Login or Register to Ask a Question