Help/Advise on parsing these line of text


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help/Advise on parsing these line of text
# 8  
Old 01-22-2013
Hi,

Marvelous !!! It works like a charm. I've been trying to work out how it should be. Are you able to refer a link to try out some more examples of these. It is becoming a lot of FUN.


Code:
$: cat x
14-OCT-2012 06:38:59 * (CONNECT_DATA=(SID=test)(GLOBAL_NAME=test.mydb.com.ch)(CID=(PROGRAM=Z:\Ora6i\BIN\ifrun60.EXE)(HOST=8000XXX05004RV)(USER=mickey))) * (ADDRESS=(PROTOCOL=tcp)(HOST=11.90.24.239)(PORT=1552)) * establish * test * 0
14-OCT-2012 06:39:15 * (CONNECT_DATA=(SID=test)(GLOBAL_NAME=test.mydb.com.ch)(CID=(PROGRAM=Z:\Ora6i\BIN\RWRBE60.exe)(HOST=8000XXX05004RV)(USER=mickey))) * (ADDRESS=(PROTOCOL=tcp)(HOST=11.90.24.239)(PORT=1574)) * establish * test * 0
14-OCT-2012 06:40:48 * (CONNECT_DATA=(SID=test)(GLOBAL_NAME=test.mydb.com.ch)(CID=(PROGRAM=Z:\Ora6i\BIN\ifrun60.EXE)(HOST=8200XXX138060Z)(USER=mouse))) * (ADDRESS=(PROTOCOL=tcp)(HOST=11.217.35.94)(PORT=2525)) * establish * test * 0
14-OCT-2012 07:01:04 * (CONNECT_DATA=(CID=(PROGRAM=)(HOST=server911)(USER=oracle))(COMMAND=status)(ARGUMENTS=64)(SERVICE=test)(VERSION=135296000)) * status * 0
$: nawk -F'[=|\(|\)]' '/^[0-9]/{
>  for(i=1;i<NF;i++) {
>   d=$1; sub(/\*/,"",d);
>   if($i=="PROGRAM") { p=$(i+1); p=(p=="")?"LOCAL":p; }
 }
 printf "%s - Program: %s Host: %s User: %s\n", d,p,h,u; d=p=h=u="";;
} ' x>   if($i=="HOST")  h=$(i+1);
>   if($i=="USER") u=$(i+1);
>  }
>  printf "%s - Program: %s Host: %s User: %s\n", d,p,h,u; d=p=h=u="";;
> } ' x
14-OCT-2012 06:38:59   - Program: Z:\Ora6i\BIN\ifrun60.EXE Host: 11.90.24.239 User: mickey
14-OCT-2012 06:39:15   - Program: Z:\Ora6i\BIN\RWRBE60.exe Host: 11.90.24.239 User: mickey
14-OCT-2012 06:40:48   - Program: Z:\Ora6i\BIN\ifrun60.EXE Host: 11.217.35.94 User: mouse
14-OCT-2012 07:01:04   - Program: LOCAL Host: server911 User: oracle

- Do you mind explaining how it works or maybe check if I understand it correctly below?

nawk -F'[=|\(|\)]' '/^[0-9]/{
- This line specifies what are the delimiters? Not sure what the /^[0-9]/ means though.

- The block of codes below parse each line of string, correct?
for(i=1;i<NF;i++) {
d=$1; sub(/\*/,"",d); <-- this remove the * asterisk?
if($i=="PROGRAM") { p=$(i+1); p=(p=="")?"LOCAL"Smilie; } <-- this check if p is blank then set p=LOCAL.
if($i=="HOST") h=$(i+1);
if($i=="USER") u=$(i+1);
}
printf "%s - Program: %s Host: %s User: %s\n", d,p,h,u; d=p=h=u="";;
}


- Thanks a lot again, you've been very helpful.
# 9  
Old 01-22-2013
-F'[=|\(|\)]' - Specifying = ( ) as field separators. Since ( ) are meta-characters they should be escaped.

'/^[0-9]/ - Work only lines starting with numbers, I put this pattern because I saw a different line: status * 0

You are absolutely correct about rest of code.
# 10  
Old 01-22-2013
Quote:
Originally Posted by bipinajith
-F'[=|\(|\)]' - Specifying = ( ) as field separators. Since ( ) are meta-characters they should be escaped.
Does these characters have to escaped in case of "awk"? I don't think so.Smilie
# 11  
Old 01-23-2013
You are right, inside square brackets, the standard meta-characters lose their meaning. But outside it should be escaped. Here is an example:
Code:
$ cat infile
bipin(ajith

$ awk -F\( '{ print $1 }' infile
bipin

$ awk -F'[(]' '{ print $1 }' infile
bipin

$ awk -F( '{ print $1 }' infile
sh: Syntax error: `(' is not expected.

I hope you understood.
This User Gave Thanks to Yoda For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Text parsing

Hi All! Is it possible to convert text file: to: ? (6 Replies)
Discussion started by: y77
6 Replies

2. Shell Programming and Scripting

Parsing blocked text

I do have a flat text file that are divided into blocks. Each block is demimited by '='. I would like to parse certain numbers and letters. This is the format of the file I have. It has thousands of such blocks >A B 1, 100 TTTT 100 95 >C D 1, 95 GHJKL = >A B 1, 72 GHUJKLO 72 84 >C D... (3 Replies)
Discussion started by: Kanja
3 Replies

3. Shell Programming and Scripting

Parsing text file

Hi Friends, I am back for the second round today - :D My input text file is this way Home friends friendship meter Tools Mirrors Downloads My Data About Us Help My own results BLAT Search Results ACTIONS QUERY SCORE START END QSIZE IDENTITY CHRO STRAND ... (7 Replies)
Discussion started by: jacobs.smith
7 Replies

4. Shell Programming and Scripting

Parsing and filtering multiline text into comma separated line

I have a log file that contains several reports with following format. <Start of delimiter> Report1 header Report1 header continue Report1 header continue Record1 header Record1 header continue Record1 header continue field1 field2 field3 field4 ------... (1 Reply)
Discussion started by: yoda9691
1 Replies

5. UNIX for Dummies Questions & Answers

Parsing file, reading each line to variable, evaluating date/time stamp of each line

So, the beginning of my script will cat & grep a file with the output directed to a new file. The data I have in this file needs to be parsed, read and evaluated. Basically, I need to identify the latest date/time stamp and then calculate whether or not it is within 15 minutes of the current... (1 Reply)
Discussion started by: hynesward
1 Replies

6. Programming

Parsing a Text file using C++

I was trying to parse the text file, which will looks like this ###XYZABC#### ############ int = 4 char = 1 float = 1 . . ############ like this my text file will contains lots of entries and I need to store these entries in the map eg. map.first = int and map.second = 4 same way I... (5 Replies)
Discussion started by: agupta2
5 Replies

7. Shell Programming and Scripting

Parsing text

Hello all, I have some text formatted as follows Name: John doe Company: Address 1: 7 times the headache Address 2: City: my city State/Province: confusion Zip/Postalcode: 12345 and I'm trying to figure out how I could extract the data after the colon so that the result would be ... (6 Replies)
Discussion started by: mcgrailm
6 Replies

8. Shell Programming and Scripting

Perl question, parsing line by line

Hello, Im very new to PERL and as a project to work on developing my skills at PERL Im trying to parse poker hands. Ive tried many methods however I cant get the last step. $yourfile= 'FILENAME';#poker hands to parse open (FILE, "$yourfile") or die $!; @lines = <FILE>; for (@lines) ... (1 Reply)
Discussion started by: Ek0
1 Replies

9. Shell Programming and Scripting

Parsing text from file

Any ideas? 1)loop through text file 2)extract everything between SOL and EOL 3)output files, for example: 123.txt and 124.txt for the file below So far I have: sed -n "/SOL/,/EOL/{p;/EOL/q;}" file Here is an example of my text file. SOL-123.go something goes here something goes... (0 Replies)
Discussion started by: ndnkyd
0 Replies

10. UNIX for Dummies Questions & Answers

Parsing text from one line with shell scripts

Hi Gurus! I wonder if anyone can help me, I'm sure you guys can. I have a text file which contains a lot of data on the one line as follows: $ What I need to do is pull all of those id values out (eg 2549425) and write them to a list in a text file. Any help would be greatly... (3 Replies)
Discussion started by: th3g0bl1n
3 Replies
Login or Register to Ask a Question