sed & awk assistance

I need some help parsing out some information produced by running a command.  I have a script that does this for one of the commands, but the one I'm working with is a little more complicated (especially when you don't really know sed or awk).  I'm going to give all the information for what I need to get out, plus provide the example of what we're already using below for one of the other commands.  

Please keep in mind that I run a command to produce this output, so it's not just a static file.  I run the command and put it in an environment variable.  Depending on the servers I run it on the output will be different, but always in this same format.  Also, the end output can have spaces between the Node and Application server if it makes it any easier - but bottom line is I just want one line for each Node/AppServer.

Thanks!  Lisa

*** THIS IS THE CURRENT OUTPUT FROM THE COMMAND ****
{/Node:cscx0102/ApplicationServer:Default Server/} /Node:cscx0102/ApplicationServer:SpherionServer/
/Node:cscx0103/ApplicationServer:SpherionServer/ /Node:cscx0102/ApplicationServer:TestServer/ /Node:
cscx0103/ApplicationServer:TestServer/ /Node:cscx0102/ApplicationServer:DeleteMeServerGroup/ /Node:c
scx0102/ApplicationServer:DeleteMeServer/

**** WHAT I NEED THE OUTPUT ABOVE TO LOOK LIKE ****

cscx0102:Default Server
cscx0102:SpherionServer
cscx0103:SpherionServer
cscx0102:TestServer
cscx0103:TestServer
cscx0102:DeleteMeServerGroup
cscx0102:DeleteMeServer/


***** EXAMPLE OF WORKING SCRIPT AND ITS OUTPUT ******

****** SCRIPT THAT WORKS *******

print
print "*** Server Groups ***"
for SVRGRP in $(wscp.sh -p $WASHOME/bin/scripts/default.wscprc -c "ServerGroup list")
do
echo $SVRGRP | sed 's/^.* ServerGroup *//'|awk -F':' '{print $2}'|sed 's/ //g'
done

print


***** THE OUTPUT OF THE "wscp.sh" COMMAND ABOVE FROM THE COMMAND LINE *****

/ServerGroup:SpherionServerGroup/ /ServerGroup:TestServerGroup/ /ServerGroup:DeleteMeServerGroup/


***** THE OUTPUT WHEN RUNNING THE SCRIPT ABOVE *******

*** Server Groups ***
SpherionServerGroup/
TestServerGroup/
DeleteMeServerGroup/
lphillips120898Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

elfieCommented:
some comments:

if you 'have' to use the wscp.sh script, obviously some data is missing. If this script doesn't return the "cscx0102" part, you can't process it.

secondly in the command "echo $SVRGRP | sed 's/^.* ServerGroup *//'|awk -F':' '{print $2}'|sed 's/ //g'"
i don't see why you must use the first "sed", the awk print $2 will strip it any way.

Also the usage of the second sed "sed 's/ //g'" is strange. This will also remove the space out of "Default server".

can you share also the wscp.sh script, or give the 'real' input data (if it's an ascii flat file.)
0
lphillips120898Author Commented:
elfie,

We have to use the WSCP command.  This is a command line tool for WebSphere that queries the repository database and return the "string" based on the query (application server list, server group list, etc.).  So having the wscp.sh would be useless without WebSphere.

I'm not quite sure what your talking about when you said the script doesn't return the "cscx0102" part.  I see it listed in this section above:

*** THIS IS THE CURRENT OUTPUT FROM THE COMMAND ****

I have NO idea why that command is the way it is.  I don't know sed or awk (although I'm trying to learn).  This is taken from another script.  I can't figure out what the "^.*" part means.

Anyway, if you know a better way to do it feel free to change the syntax.  I believe if you pass the OUTPUT above to a variable (i.e. like SVRGRP) and then run whatever you think the appropriate command to strip out what is needed then it should work - I just don't know what the heck I'm doing.  The example below was easier because it didn't have as many parameters to deal with (only needed to display the ServerGroup), this has two things that need to be displayed - the Node and ApplicationServer.

Thanks for your help,

Lisa
0
ilikenineCommented:
try this.

if it doesnot give the exact things you are expecting, try changing the 3 and 5 to some other number...


for SVRGRP in $(wscp.sh -p $WASHOME/bin/scripts/default.wscprc -c "ServerGroup list")
do
echo $SVRGRP | sed "s/:/\//g" | awk '{FS="\/"}{print $3":"$5}'
done

enjoy
ilikening

0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

ilikenineCommented:
for SVRGRP in $(your command)
do
echo $SVRGRP | sed "s/:/\//g" | awk '{FS="\/"}{print $3":"$5}'
done

thanks
ilikenine
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lphillips120898Author Commented:
ilikenine,

Great Job!  I'm going to go ahead and give you the points... but if you can give me some insight on how to get rid of the ":" on the second line I would appreciate it.  Lisa


THE OUTPUT FROM YOUR COMMAND
*** Application Servers ***
cscx0102:Default
:
cscx0102:SpherionServer
cscx0103:SpherionServer
cscx0102:TestServer
cscx0103:TestServer
cscx0102:DeleteMeServerGroup
cscx0102:DeleteMeServer
cscx0102:MyTestServer
0
ilikenineCommented:
That space is coming b'coz of the space in between the Default and Server.
I was expecting it to be "DefaultServer" while it is "Default Server".

Get rid of that space and you are done.

-ilikenine
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.