[Gllug] parsing command output
Gavin White
white.gavin at gmail.com
Wed Feb 14 17:36:49 UTC 2007
In large print, for those of us who can't do shorthand,
$CMD 2>&1 |strings |head -8 |tail -2 |tr -s " " "," |cut -d"," -f 5
$CMD #your command
2>&1 #redirect stderr to stdout
|strings #remove blank lines
|head -8 #get the first 8 lines
|tail -2 #get the last 2 of those lines
|tr -s " " "," #collapse all (non tab) whitespace to a comma (tab would be \t)
|cut -d"," -f 5 #get the field you want
Gavin
On 2/14/07, Alain Williams <addw at phcomp.co.uk> wrote:
> On Wed, Feb 14, 2007 at 06:31:09PM +0100, salsaman wrote:
> > Hi all,
> > I need a little bash script that should do the following -
> > run a program and parse the output on stderr. It needs to write the
> > fourth field of the 7th and 8th lines to a file. Fields are separated by
> > one or more spaces and lines can also start with a space.
> >
> > E.g. if the output of command "foo" on stderr is:
> >
> > 1abc
> > 2def
> > 3abc
> > 4def
> > 5abc
> > 6 mmmm
> > 7abc 123 56 1024 xxx
> > 8abc 123 56 768 yyy
> > 9 aaa
> >
> > then the result in out.txt should be:
> > 1024
> > 768
>
> Untested, but how about:
>
> foo > Output 2>&1 | sed -e 1,6d -e 9q -e 's/^ *[^ ]+ *[^ ]+ *[^ ]+ *\([^ ]+\).*/\1/'
>
> --
> Alain Williams
> Linux Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer.
> +44 (0) 787 668 0256 http://www.phcomp.co.uk/
> Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php
> #include <std_disclaimer.h>
>
> --
> Gllug mailing list - Gllug at gllug.org.uk
> http://lists.gllug.org.uk/mailman/listinfo/gllug
>
>
--
Gllug mailing list - Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug
More information about the GLLUG
mailing list