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
# 1  
Old 01-22-2013
Help/Advise on parsing these line of text

Hi,

Can anyone please advise how do I parse the following line of strings?

Code:
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

- I am wanting parse or de-construct it so that I can get the HOST, PROGRAM and USER

- awk's -F and cut only accept single delimiter so am lost on how to parse these strings.

- Feedback/advise much appreciated. Thanks in advance.
# 2  
Old 01-22-2013
posted the same again!!!

Don't do like this.
# 3  
Old 01-22-2013
Code:
awk -F'[=|\(|\)]' '{
 for(i=1;i<NF;i++) {
  if($i=="PROGRAM") p=$(i+1);
  if($i=="HOST") h=$(i+1);
  if($i=="USER") u=$(i+1);
 }
 printf "Program: %s Host: %s User: %s\n", p,h,u;
} ' file

# 4  
Old 01-22-2013
Quote:
Originally Posted by PikK45
posted the same again!!!

Don't do like this.
Sorry Pikk45,

I thought they are different question so I posted it twice, the first one is where I was not even able to read a single line of string.

My apology.

---------- Post updated at 09:46 PM ---------- Previous update was at 09:39 PM ----------

Quote:
Originally Posted by bipinajith
Code:
awk -F'[=|\(|\)]' '{
 for(i=1;i<NF;i++) {
  if($i=="PROGRAM") p=$(i+1);
  if($i=="HOST") h=$(i+1);
  if($i=="USER") u=$(i+1);
 }
 printf "Program: %s Host: %s User: %s\n", p,h,u;
} ' file


Hi,

I tried your suggestion and it does not print anything.

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
$: awk -F'[=|\(|\)]' '{
>  for(i=1;i<NF;i++) {
>   if($i=="PROGRAM") p=$(i+1);
>   if($i=="HOST") h=$(i+1);
>   if($i=="USER") u=$(i+1);
>  }
>  printf "Program: %s Host: %s User: %s\n", p,h,u;
> } ' x
Program:  Host:  User:
Program:  Host:  User:
Program:  Host:  User:
Program:  Host:  User:
Program:  Host:  User:
$:

I am on Solaris, I also tried using FS like the one below

Code:
 
$: awk 'BEGIN { FS="(PROGRAM=" } { print $2 }' x
CONNECT_DATA=
CONNECT_DATA=
CONNECT_DATA=
CONNECT_DATA=

- Looks like my awk doesn't like multiple delimiters Smilie

---------- Post updated at 09:48 PM ---------- Previous update was at 09:46 PM ----------

Hi,

Didn't realize I can simply do awk file and didn't necessarily need to read line by line.

Looks like the first post is not necessary at all.

Last edited by newbie_01; 01-23-2013 at 12:03 AM..
# 5  
Old 01-22-2013
For Solaris or SunOS use nawk
This User Gave Thanks to Yoda For This Post:
# 6  
Old 01-22-2013
Thanks a lot, using nawk works like a charm

---------- Post updated at 10:05 PM ---------- Previous update was at 09:56 PM ----------

Hi,

How do I include the timestamp on the printf? And if the program is null/zero-length print LOCAL instead.

Currently the output is as below:


Code:
Program: Z:\Ora6i\BIN\ifrun60.EXE Host: 11.90.24.239 User: mickey
Program: Z:\Ora6i\BIN\RWRBE60.exe Host: 11.90.24.239 User: mickey
Program: Z:\Ora6i\BIN\ifrun60.EXE Host: 11.217.35.94 User: mouse
Program:  Host: server911 User: oracle

How to make it look like the one below?

Code:
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

Thanks again for your help.
# 7  
Old 01-22-2013
Code:
nawk -F'[=|\(|\)]' '/^[0-9]/{
 for(i=1;i<NF;i++) {
  d=$1; sub(/\*/,"",d);
  if($i=="PROGRAM") { p=$(i+1); p=(p=="")?"LOCAL":p; }
  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="";;
} ' file

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