•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 456,447 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,666 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 474 | Replies: 2
![]() |
•
•
Join Date: Nov 2007
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
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
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.
•
•
Join Date: Oct 2007
Posts: 306
Reputation:
Rep Power: 2
Solved Threads: 29
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
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!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
•
•
Join Date: Oct 2007
Posts: 302
Reputation:
Rep Power: 3
Solved Threads: 37
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.
You can use a combination of awk '/pattern/' , awk -F"delimiter" and grep -f patternsinfile file
to get the results you need.
Good Luck.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Shell Scripting Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- what is the best scripting language? (Computer Science and Software Design)
- Obtain Remote Assistance by Sending an E-mail Message in Windows XP (Windows tips 'n' tweaks)
- vBulletin technical assistance (Existing Scripts)
- Obtain Remote Assistance by Sending an E-mail Message in Windows XP (Windows tips 'n' tweaks)
- Cannot Use MSN EXPLORER or AOL To Send a Remote Assistance Invitation (Windows tips 'n' tweaks)
- Obtain Remote Assistance Using Windows Messenger in Windows XP (Windows tips 'n' tweaks)
Other Threads in the Shell Scripting Forum
- Previous Thread: need help with figuring out sizeof in bash script
- Next Thread: puzzled by scripts


Linear Mode