need scripting assistance

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2007
Posts: 1
Reputation: noamb is an unknown quantity at this point 
Solved Threads: 0
noamb noamb is offline Offline
Newbie Poster

need scripting assistance

 
0
  #1
Nov 21st, 2007
Hello all,

I need to write a script that will act upon output formatted like the following example:

afp:state = "RUNNING"
afp:usersArray:_array_index:0:disconnectID = 0
afp:usersArray:_array_index:0:sessionID = 3423
afp:usersArray:_array_index:0:minsToDisconnect = 0
afp:usersArray:_array_index:0:flags = 0
afp:usersArray:_array_index:0:state = 6
afp:usersArray:_array_index:0:loginElapsedTime = 89731
afp:usersArray:_array_index:0:name = "maryallen"
afp:usersArray:_array_index:0:lastUseElapsedTime = 89725
afp:usersArray:_array_index:0:serviceType = "afp"
afp:usersArray:_array_index:0:sessionType = "tcp"
afp:usersArray:_array_index:0:ipAddress = "10.0.3.36"
afp:usersArray:_array_index:1:disconnectID = 0
afp:usersArray:_array_index:1:sessionID = 3573
afp:usersArray:_array_index:1:minsToDisconnect = 0
afp:usersArray:_array_index:1:flags = 0
afp:usersArray:_array_index:1:state = 6
afp:usersArray:_array_index:1:loginElapsedTime = 72783
afp:usersArray:_array_index:1:name = "ILS"
afp:usersArray:_array_index:1:lastUseElapsedTime = 68964
afp:usersArray:_array_index:1:serviceType = "afp"
afp:usersArray:_array_index:1:sessionType = "tcp"
afp:usersArray:_array_index:1:ipAddress = "10.0.3.136"
afp:usersArray:_array_index:2:disconnectID = 0
afp:usersArray:_array_index:2:sessionID = 3609
afp:usersArray:_array_index:2:minsToDisconnect = 0
afp:usersArray:_array_index:2:flags = 0
afp:usersArray:_array_index:2:state = 1
afp:usersArray:_array_index:2:loginElapsedTime = 69026
afp:usersArray:_array_index:2:name = "samanthacovey"
afp:usersArray:_array_index:2:lastUseElapsedTime = 36404
afp:usersArray:_array_index:2:serviceType = "afp"
afp:usersArray:_array_index:2:sessionType = "tcp"
afp:usersArray:_array_index:2:ipAddress = "10.0.3.36"
afp:usersArray:_array_index:3:disconnectID = 0
afp:usersArray:_array_index:3:sessionID = 3664
afp:usersArray:_array_index:3:minsToDisconnect = 0
afp:usersArray:_array_index:3:flags = 0
afp:usersArray:_array_index:3:state = 1
afp:usersArray:_array_index:3:loginElapsedTime = 5745
afp:usersArray:_array_index:3:name = "dawndawson"
afp:usersArray:_array_index:3:lastUseElapsedTime = 1
afp:usersArray:_array_index:3:serviceType = "afp"
afp:usersArray:_array_index:3:sessionType = "tcp"
afp:usersArray:_array_index:3:ipAddress = "10.0.3.56"
afp:usersArray:_array_index:4:disconnectID = 0
afp:usersArray:_array_index:4:sessionID = 3666
afp:usersArray:_array_index:4:minsToDisconnect = 0
afp:usersArray:_array_index:4:flags = 0
afp:usersArray:_array_index:4:state = 1
afp:usersArray:_array_index:4:loginElapsedTime = 5743
afp:usersArray:_array_index:4:name = "dawndawson"
afp:usersArray:_array_index:4:lastUseElapsedTime = 519
afp:usersArray:_array_index:4:serviceType = "afp"
afp:usersArray:_array_index:4:sessionType = "tcp"
afp:usersArray:_array_index:4:ipAddress = "10.0.3.56"
afp:usersArray:_array_index:5:disconnectID = 0
afp:usersArray:_array_index:5:sessionID = 3698
afp:usersArray:_array_index:5:minsToDisconnect = 0
afp:usersArray:_array_index:5:flags = 0
afp:usersArray:_array_index:5:state = 1
afp:usersArray:_array_index:5:loginElapsedTime = 2276
afp:usersArray:_array_index:5:name = "kateberrigan"
afp:usersArray:_array_index:5:lastUseElapsedTime = 0
afp:usersArray:_array_index:5:serviceType = "afp"
afp:usersArray:_array_index:5:sessionType = "tcp"
afp:usersArray:_array_index:5:ipAddress = "10.0.3.33"
afp:usersArray:_array_index:6:disconnectID = 0
afp:usersArray:_array_index:6:sessionID = 3700
afp:usersArray:_array_index:6:minsToDisconnect = 0
afp:usersArray:_array_index:6:flags = 0
afp:usersArray:_array_index:6:state = 1
afp:usersArray:_array_index:6:loginElapsedTime = 2273
afp:usersArray:_array_index:6:name = "kateberrigan"
afp:usersArray:_array_index:6:lastUseElapsedTime = 1604
afp:usersArray:_array_index:6:serviceType = "afp"
afp:usersArray:_array_index:6:sessionType = "tcp"
afp:usersArray:_array_index:6:ipAddress = "10.0.3.33"
afp:usersArray:_array_index:7:disconnectID = 0
afp:usersArray:_array_index:7:sessionID = 3705
afp:usersArray:_array_index:7:minsToDisconnect = 0
afp:usersArray:_array_index:7:flags = 1
afp:usersArray:_array_index:7:state = 1
afp:usersArray:_array_index:7:loginElapsedTime = 607
afp:usersArray:_array_index:7:name = "sabrinaschwartz"
afp:usersArray:_array_index:7:lastUseElapsedTime = 1
afp:usersArray:_array_index:7:serviceType = "afp"
afp:usersArray:_array_index:7:sessionType = "tcp"
afp:usersArray:_array_index:7:ipAddress = "10.0.3.28"
afp:usersArray:_array_index:8:disconnectID = 0
afp:usersArray:_array_index:8:sessionID = 3707
afp:usersArray:_array_index:8:minsToDisconnect = 0
afp:usersArray:_array_index:8:flags = 1
afp:usersArray:_array_index:8:state = 1
afp:usersArray:_array_index:8:loginElapsedTime = 606
afp:usersArray:_array_index:8:name = "sabrinaschwartz"
afp:usersArray:_array_index:8:lastUseElapsedTime = 207
afp:usersArray:_array_index:8:serviceType = "afp"
afp:usersArray:_array_index:8:sessionType = "tcp"
afp:usersArray:_array_index:8:ipAddress = "10.0.3.28"
afp:timeStamp = "2007-11-21 10:05:40 -0800"


The script needs to:

1. find any line that ends with "state = 6"
2. extract the "array_index:" number from that line
3. extract the "sessionID" of that array_index from another line

This goes beyond my knowledge of grep and awk. I would use awk except I only know how to act on columns, and since there's no whitespace around the array_index value I'm stumped! Can you help?

Thanks!
noam
Last edited by noamb; Nov 21st, 2007 at 2:26 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 399
Reputation: eggi will become famous soon enough eggi will become famous soon enough 
Solved Threads: 47
eggi eggi is offline Offline
Posting Whiz

Re: need scripting assistance

 
0
  #2
Nov 21st, 2007
Hey There,

If your issue is with awk, you could double up on awk (pipe one command to the other) and just change your default delimiter for the one search to the ":" symbol, like:
awk -F":" '{print $4}' <-- for example <-- not specific to your script. You might not even have to pipe two awks together, just split the strings separately.

Being somewhat general to help you out since you seem to just about have it. Let me know if I can help any more. I think once you've got the -F delimiter setting worked out, you'll be all set parsing this with awk.

, Mike
Last edited by eggi; Nov 21st, 2007 at 7:24 pm.
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 305
Reputation: stilllearning has a spectacular aura about stilllearning has a spectacular aura about 
Solved Threads: 43
stilllearning stilllearning is offline Offline
Posting Whiz

Re: need scripting assistance

 
0
  #3
Nov 22nd, 2007
This is interesting, and I was able to solve it using a couple of passes with pipes. For me its just easier to break it up into the steps that you explained and go through them one by one, and use temp files if needed.

You can use a combination of awk '/pattern/' , awk -F"delimiter" and grep -f patternsinfile file
to get the results you need.

Good Luck.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC