How do I parse the output of a command that output to standard out?
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.
How do I parse the output of a command that output to standard out?
I am currently trying to take the output, written to standard out, of one of our programs and reformat it in a way that is more useful to those in my group. It has proven difficult to get the actual program re-written (the usual delays) so I believe I should able to accomplish this via a shell script. The one restriction I have is that this will using Busy Box with a limited toolset.
Anyway the real point of this question is figure out… When doing this type of parsing via a shell script do I need to send the output to a file a then parse that or can I parse it directly from standard out?
I have a background in programming but haven’t used in some time so its time get into it. I see this as a both easy (the hard work is done via the program) and hard (I will have to do conditional testing to more the data correctly).
Many Thanks (if you need more info, I'm sure you will, just let me know)
You can merely pipe the output to a new command (awk or sed, for instance), or you can wrap the entire script process within another script (such as a perl script that can parse the output using backticks).
For very short output you can just use something like this:
VALUE="$(your_command)"
For mulitple lines you'll find it easier to use a pipe or redirect the output to a file for further processing. Sometimes it's useful to use the 'tee' program for this, if you want to see the output as well as put it in a file.
OK, so an oversight isn't exactly the end of the world.
If you share your output, trying to make sure that it's truely representative of your file, then we can have a bit of a think about it while you are doing the same. That way if you come up empty or with a less than optimal solution then there might be a ready solution to your problem all thought out ahead of time.
well after toying around the the system i found that the sys already has a cvs file with this info in it so there is no need for me to reinvent the wheel. Now have to develop a script to parse this file. Thanks for the help and I sure I'll be back when I dig into that.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.