ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I need to condense the output of this file to send to SiteScope as a file with only values of either <0 or >0. Meaning, if the state:reachable it needs to appear as >0. if state:unreachable than the value needs to appear as <0. I basically need to find a way to remove all erroneous info and substitute the words state:reachable or state:unreachable with either <0 or >0. I have tried many different methods, awk, sed and grep but seem to come up short. Any help would be most appreciative and would be a great learning tool.
Thanks! I think we are almost there. The only think I did to the script was change the values the other way around. 'BEGIN{OFS=FS="-"}{if($2 ~ /state:reachable/)$2 = ">0";if($2 ~ /state:unreachable/)$2 = "<0"}1'
So now the output looks like which is correct given the >0 means state:reachable.
I don't need the other data. I have tried some sed commands to remove, but I don't know how to remove the random numbers associated with the output, for example the numbers which appear after partition:199 or server names with numbers, for example nc2sz2ecmas19 or nc3sz2ecmas10.
Thanks for your help so far on this, I received further clarification as
to what I need to do and I think it requires a little tweaking. For the
ones that are "state:reachable" I don't need any value returned, or
maybe a simple echo statement that says "reachable" or a numeric value
of "-1". I can change it if necessary.. For the ones that are in
"state:unreachable". I need a count of how many return like that. Say
5,6,7, or so on. So the output I am interested in is:
-1 (good)
or
5 (bad)
This is the script so far that I have. For a reference point.
#the values -p -bp and -ch will need to be altered according to what
needs to be run.
/hosting/ogsa/ogsa-6.1.0.5/ObjectGrid/bin/xsadmin.sh -p 11111 -bp 11111
-ch server0123 -routetable | sed -e 's/.*state:reachable.*/>0/' e
's/.*state:unreachable.*/<0/' > `date "+%y%m%d%H%M%S"`.txt
This is the output it produces in its current form. It counts the number of hosts on the grid. I don't need this many as an output, Just the ones from above in that format.
I don't understand, so you want it to print the number of "unreachable" lines if there are any, and print "-1" if there aren't any?
Do you still want the ">0" and "<0" written the the text file, like in your script in the above post?
Yeah sorry, I received more specific information and basically the values need to be changed. Sitescope won't recognize the <0 or >0 repeated many lines over. I just need one value to indicate all are reachable and one numeric value to indicate how many are unreachable, say 5 or so. So out put would be say:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.