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



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-21-2007
Registered User
 

Join Date: Nov 2007
Posts: 1
need scripting help

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
Sponsored Links
  #2 (permalink)  
Old 11-21-2007
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,199
something along these lines.....
nawk -f noa.awk myFile

noa.awk:

Code:
BEGIN {
  FS="( |:|=)"
  FLDidx=4
  FLDname=5
}

{
  if ( $FLDname == "state" && $NF == "6" )
     state6[$FLDidx]
  if ( $FLDname == "sessionID" )
     sessionID[$FLDidx] = $NF
}
END {
  for (i in state6)
    printf("state6 idx->[%d] sessionID->[%d]\n", i, sessionID[i])
}

Sponsored Links
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 Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
ksh scripting help praveenbvarrier Shell Programming and Scripting 1 04-15-2008 11:19 AM
sql scripting help sam786 Shell Programming and Scripting 3 12-10-2007 12:31 PM
difference between AIX shell scripting and Unix shell scripting. haroonec Shell Programming and Scripting 2 04-12-2006 09:12 AM
scripting guru's pls help me with scripting on AIX thatiprashant Shell Programming and Scripting 1 01-20-2006 07:58 PM
Scripting? woofie What's on Your Mind? 1 03-09-2005 07:03 AM



All times are GMT -4. The time now is 04:11 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-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0