need scripting help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need scripting help
# 1  
Old 11-21-2007
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
# 2  
Old 11-21-2007
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])
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Web Development

Perl scripting or shell scripting?

i am going to study any one of the scripting languages mentioned above(shell 0r perl scripting) . Which is having more scope for a fresher? (1 Reply)
Discussion started by: Anna Hussie
1 Replies

2. What is on Your Mind?

Shell Scripting vs Perl scripting

Gents, I have been working in a Solaris/Unix environment for about 9 months. I took some linux classses online before getting the job. But, I am not very good at scripting. I want to learn how to script. Do you think that I should start with Shell scripting or Perl? I wanted to continue with... (2 Replies)
Discussion started by: Pouchie1
2 Replies

3. Android

Android Scripting Environment: Shell Scripting and Android

I just upgraded to Android 2.2 from 2.1. The GPS issue that was troublesome in 2.1 seems to have been fixed. Some of web browsing seems faster, but it could just be my connection is better today ;) Flash works in some browsers but not very good and it is too slow for Flash apps designed for... (0 Replies)
Discussion started by: Neo
0 Replies

4. What is on Your Mind?

Shell scripting vs Perl scripting

Hi all, I would like to start developping some good scripting skills. Do you think it would be best to start with shell scripting or Perl? I already got a fundation, really basics, in perl. but I am wondering what would be best to be good at first. Can you please help me determine which one to... (14 Replies)
Discussion started by: Pouchie1
14 Replies

5. Shell Programming and Scripting

Call Shell scripting from Perl Scripting.

Hi How to call a shell scripting through a Perl scripting? Actually I need some value from Shell scripting and passes in the Perl scripting. So how can i do this? (2 Replies)
Discussion started by: anupdas
2 Replies

6. UNIX for Dummies Questions & Answers

Scripting Help

Hello all. Like Ive stated before, I am new to world of Unix. I was given the tast to create a script that will concatenate 20 files into one file. I know that the cat command is to be used but I am looking for something to get started on. Again, basically I need to wrtie a script that whill... (3 Replies)
Discussion started by: ndoggy020
3 Replies

7. UNIX for Advanced & Expert Users

Need help on scripting

in unix bc command is used as calculator and also for conversion, i want to convert 5f to decimal. but bc dont consider 5f as hex value it considers 5F as hex value. I get 5f from other iteration so i cant change that f to F...is there any way to convert 5f to decimal ot 5f to 5F :rolleyes: (2 Replies)
Discussion started by: abhinandantn
2 Replies

8. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies

9. Shell Programming and Scripting

scripting guru's pls help me with scripting on AIX

can someone pls help me with the script for a files coming from one system to a particular directory and i want to write a script to move those files to another directory on different system by renaming the files... pls someone help me on this... thanking in anticipation.... (1 Reply)
Discussion started by: thatiprashant
1 Replies

10. AIX

New to scripting

We have a scripting requirement, Background: On a particular path, we compress a load of log files into tar.gz. This is done on an hourly basis throughout the day and it produces files of the following format, 2005-08-05-00-021031.tar.gz as an example. This is done by a script. We need: ... (2 Replies)
Discussion started by: rajesh_149
2 Replies
Login or Register to Ask a Question