Solved

sed & awk assistance

Posted on 2002-04-18
6
444 Views
Last Modified: 2010-04-21
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/
0
Comment
Question by:lphillips120898
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 3

Expert Comment

by:elfie
ID: 6952996
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
 

Author Comment

by:lphillips120898
ID: 6953344
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
 
LVL 1

Expert Comment

by:ilikenine
ID: 6954733
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Accepted Solution

by:
ilikenine earned 100 total points
ID: 6954850
for SVRGRP in $(your command)
do
echo $SVRGRP | sed "s/:/\//g" | awk '{FS="\/"}{print $3":"$5}'
done

thanks
ilikenine
0
 

Author Comment

by:lphillips120898
ID: 6959563
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
 
LVL 1

Expert Comment

by:ilikenine
ID: 6959947
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question