?
Solved

sed & awk assistance

Posted on 2002-04-18
6
Medium Priority
?
445 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Accepted Solution

by:
ilikenine earned 400 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

770 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