The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Seems Complicated but would b happy if its possible anushree.a Shell Programming and Scripting 6 05-28-2008 05:25 AM
Sort complicated two fields lalelle Shell Programming and Scripting 3 04-17-2008 05:15 PM
complicated(?) grep khearnen UNIX for Dummies Questions & Answers 5 04-07-2008 12:03 PM
More complicated log parsing sjug Shell Programming and Scripting 25 06-13-2007 09:33 AM
Very complicated script.. rocinante Shell Programming and Scripting 5 06-08-2007 10:56 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-27-2009
sdohn sdohn is offline
Registered User
  
 

Join Date: Dec 2008
Location: Germany - Hamburg
Posts: 19
Seperate complicated fields with awk

Hello, I want to separate fields from an log output like this:


11-JUL-2008 23:14:25 * (CONNECT_DATA=(SERVICE_NAME=WUMMER.IM.HERE.EXELLENT.COM)(CID=(PROGRAM=D:\oracle\product\10.2.0\clien t_1\jdk\jre\bin\java.exe)(HOST=X900005199)(USER=FTET1))) * (ADDRESS=(PROTOCOL=tcp)(HOST=45.137.251.223)(PORT=2196)) * establish * WUMMER.IM.HERE.EXELLENT.COM * 0
11-JUL-2008 23:20:20 * (CONNECT_DATA=(SID=P1VPMHAM)(CID=(PROGRAM=)(HOST=__jdbc__)(USER=))) * (ADDRESS=(PROTOCOL=tcp)(HOST=133.52.24.148)(PORT=1462)) * establish * WUMMER * 0

into:

$1 = 11-JUL-2008 23:14:25
$2 = (CONNECT_DATA=(SERVICE_NAME=WUMMER.IM.HERE.EXELLENT.COM)
$3= (CID=(PROGRAM=D:\oracle\product\10.2.0\client_1\jdk\jre\bin\java.exe)
$4= (HOST=X900005199)
$5= (USER=FTET1)
$6= (ADDRESS=(PROTOCOL=tcp)
$7= (HOST=45.137.251.223)
$8= (PORT=2196)

I've tried to play with the FS seperator with mixed results:
awk -F'(*[^(]*)' '{ print $1 " " $2 " " $3 }' listener.log

Anyone an idea for me, I think i need the correct regular expression.
  #2 (permalink)  
Old 01-27-2009
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink This may start you off...

What I did was replace any ( with ~( so I could use the ~ as a delimiter.


> cat file149
11-JUL-2008 23:14:25 * (CONNECT_DATA=(SERVICE_NAME=WUMMER.IM.HERE.EXELLENT.COM)(CID=(PROGRAM=D:\oracle\product\10.2.0\clien t_1\jdk\jre\bin\java.exe)(HOST=X900005199)(USER=FTET1))) * (ADDRESS=(PROTOCOL=tcp)(HOST=45.137.251.223)(PORT=2196)) * establish * WUMMER.IM.HERE.EXELLENT.COM * 0
11-JUL-2008 23:20:20 * (CONNECT_DATA=(SID=P1VPMHAM)(CID=(PROGRAM=)(HOST=__jdbc__)(USER=))) * (ADDRESS=(PROTOCOL=tcp)(HOST=133.52.24.148)(PORT=1462)) * establish * WUMMER * 0

Code:
> sed "s/(/~(/g" <file149 >file149.a
> awk -F"~" '{print "1="$1,"\n2="$2$3,"\n3="$4$5,"\n4="$6,"\n5="$7"\n"}' file149.a
1=11-JUL-2008 23:14:25 *  
2=(CONNECT_DATA=(SERVICE_NAME=WUMMER.IM.HERE.EXELLENT.COM) 
3=(CID=(PROGRAM=D:\oracle\product\10.2.0\clien t_1\jdk\jre\bin\java.exe) 
4=(HOST=X900005199) 
5=(USER=FTET1))) * 

1=11-JUL-2008 23:20:20 *  
2=(CONNECT_DATA=(SID=P1VPMHAM) 
3=(CID=(PROGRAM=) 
4=(HOST=__jdbc__) 
5=(USER=))) *
  #3 (permalink)  
Old 01-27-2009
sdohn sdohn is offline
Registered User
  
 

Join Date: Dec 2008
Location: Germany - Hamburg
Posts: 19
Quote:
Originally Posted by joeyg View Post
What I did was replace any ( with ~( so I could use the ~ as a delimiter.
Thanks a lot User joeyg for your solution, now I can further remove what I'm not wanting on the lines.

brgds from User sdohn
  #4 (permalink)  
Old 01-27-2009
quirkasaurus's Avatar
quirkasaurus quirkasaurus is offline
Registered User
  
 

Join Date: Jan 2009
Location: canton, michigan
Posts: 373
an inelegant solution

Forget regular expressions. That isn't going to happen.
What you should probably do... is explain what you eventually want to do with
the variables. My initial questions are:
why awk?
why do they have to be in positions $1 through $8?
Once there, what do you want to do with them?
My point is -- the end result is what you're after -- hopefully -- not
whether we can put them in positions 1 through 8 for awk to do something with.
However, taking this nasty log file and converting it to your whims, like so:

cat << EOF |
11-JUL-2008 23:14:25 * (CONNECT_DATA=(SERVICE_NAME=WUMMER.IM.HERE.EXELLENT.COM)(CID=(PROGRAM=D:\oracle\product\10.2.0\clien t_1\jdk\jre\bin\java.exe)(HOST=X900005199)(USER=FTET1))) * (ADDRESS=(PROTOCOL=tcp)(HOST=45.137.251.223)(PORT=2196)) * establish * WUMMER.IM.HERE.EXELLENT.COM * 0
11-JUL-2008 23:20:20 * (CONNECT_DATA=(SID=P1VPMHAM)(CID=(PROGRAM=)(HOST=__jdbc__)(USER=))) * (ADDRESS=(PROTOCOL=tcp)(HOST=133.52.24.148)(PORT=1462)) * establish * WUMMER * 0
EOF
###---------------------------------------
### retain space for date, removed later on
###---------------------------------------
sed -e 's/ /@/' \
-e 's/)/) /g' \
|
###---------------------------------------
### convert all spaces to newlines
###---------------------------------------
tr ' ' '\012' |
###---------------------------------------
### delete blank lines, asterisk only lines and parenthise only lines
###---------------------------------------
sed -e '/^$/d' \
-e '/^\*/d' \
-e '/^)$/d' \
|
###---------------------------------------
### some line numbering...
###---------------------------------------
nl -nln |
###---------------------------------------
### grab only the 1-8 "fields"
###---------------------------------------
grep '^[1-8] ' |
###---------------------------------------
### convert to one line
###---------------------------------------
while read num line; do
print -n "$line "
if [ $num -eq 8 ]; then
print
fi
done |
###---------------------------------------
### and there they are... in positions 1-8
###---------------------------------------
awk 'BEGIN{ OFS="|"; }
{ print( $1, $2, $3, $4, $5, $6, $7, $8 ); }' |
###---------------------------------------
### oh. and remove the at sign for the date.
###---------------------------------------
sed -e 's/@/ /'


It's a complex mess, indeed.

Last edited by quirkasaurus; 01-27-2009 at 11:52 AM..
  #5 (permalink)  
Old 01-27-2009
sdohn sdohn is offline
Registered User
  
 

Join Date: Dec 2008
Location: Germany - Hamburg
Posts: 19
Quote:
Originally Posted by quirkasaurus View Post
Forget regular expressions. That isn't going to happen.
What you should probably do... is explain what you eventually want to do with
the variables. My initial questions are:
why awk?
why do they have to be in positions $1 through $8?
Once there, what do you want to do with them?
My point is -- the end result is what you're after -- hopefully -- not
whether we can put them in positions 1 through 8 for awk to do something with.
However, taking this nasty log file and converting it to your whims, like so:
Thank you for your solution to this complex problem.
The reason for me was to seperate the Values for putting them in a database. Now I can do a report with sql with the data.

brgds from user sdohn
  #6 (permalink)  
Old 01-27-2009
quirkasaurus's Avatar
quirkasaurus quirkasaurus is offline
Registered User
  
 

Join Date: Jan 2009
Location: canton, michigan
Posts: 373
i like the tilde solution, too. even better!

but figured i'd post mine anyways -- hopefully some of the ideas are valuable...
  #7 (permalink)  
Old 01-27-2009
quirkasaurus's Avatar
quirkasaurus quirkasaurus is offline
Registered User
  
 

Join Date: Jan 2009
Location: canton, michigan
Posts: 373
Cool. Then the script is useful. It converts everything to a pipe-delimited output.
Just load from there.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:49 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0