[Gllug] parsing command output

Alain Williams addw at phcomp.co.uk
Wed Feb 14 17:17:25 UTC 2007


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>
-------------- next part --------------
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug


More information about the GLLUG mailing list