Solved

sed & awk assistance

Posted on 2002-04-18
6
438 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
  • 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now