lphillips120898
asked on
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/Applicatio nServer:De fault Server/} /Node:cscx0102/Application Server:Sph erionServe r/
/Node:cscx0103/Application Server:Sph erionServe r/ /Node:cscx0102/Application Server:Tes tServer/ /Node:
cscx0103/ApplicationServer :TestServe r/ /Node:cscx0102/Application Server:Del eteMeServe rGroup/ /Node:c
scx0102/ApplicationServer: DeleteMeSe rver/
**** WHAT I NEED THE OUTPUT ABOVE TO LOOK LIKE ****
cscx0102:Default Server
cscx0102:SpherionServer
cscx0103:SpherionServer
cscx0102:TestServer
cscx0103:TestServer
cscx0102:DeleteMeServerGro up
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/defau lt.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:SpherionServe rGroup/ /ServerGroup:TestServerGro up/ /ServerGroup:DeleteMeServe rGroup/
***** THE OUTPUT WHEN RUNNING THE SCRIPT ABOVE *******
*** Server Groups ***
SpherionServerGroup/
TestServerGroup/
DeleteMeServerGroup/
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/Applicatio
/Node:cscx0103/Application
cscx0103/ApplicationServer
scx0102/ApplicationServer:
**** WHAT I NEED THE OUTPUT ABOVE TO LOOK LIKE ****
cscx0102:Default Server
cscx0102:SpherionServer
cscx0103:SpherionServer
cscx0102:TestServer
cscx0103:TestServer
cscx0102:DeleteMeServerGro
cscx0102:DeleteMeServer/
***** EXAMPLE OF WORKING SCRIPT AND ITS OUTPUT ******
****** SCRIPT THAT WORKS *******
print "*** Server Groups ***"
for SVRGRP in $(wscp.sh -p $WASHOME/bin/scripts/defau
do
echo $SVRGRP | sed 's/^.* ServerGroup *//'|awk -F':' '{print $2}'|sed 's/ //g'
done
***** THE OUTPUT OF THE "wscp.sh" COMMAND ABOVE FROM THE COMMAND LINE *****
/ServerGroup:SpherionServe
***** THE OUTPUT WHEN RUNNING THE SCRIPT ABOVE *******
*** Server Groups ***
SpherionServerGroup/
TestServerGroup/
DeleteMeServerGroup/
ASKER
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
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
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/defau lt.wscprc -c "ServerGroup list")
do
echo $SVRGRP | sed "s/:/\//g" | awk '{FS="\/"}{print $3":"$5}'
done
enjoy
ilikening
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/defau
do
echo $SVRGRP | sed "s/:/\//g" | awk '{FS="\/"}{print $3":"$5}'
done
enjoy
ilikening
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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:DeleteMeServerGro up
cscx0102:DeleteMeServer
cscx0102:MyTestServer
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:DeleteMeServerGro
cscx0102:DeleteMeServer
cscx0102:MyTestServer
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
I was expecting it to be "DefaultServer" while it is "Default Server".
Get rid of that space and you are done.
-ilikenine
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.)