[Gllug] parsing command output

salsaman at xs4all.nl salsaman at xs4all.nl
Wed Feb 14 21:16:19 UTC 2007


On Wed, February 14, 2007 21:27, Tethys wrote:
>
> Stuart Sears writes:
>
>>command 3>&1 2>&3 > /dev/null | sed -n '7,8p'| awk '{print $4}' >
>> outputfile
>>
>> [...]
>>
>>I sort of understand it, but I am probably going to have to go back and
>>read it all again a few times.
>
> Yes indeed. Your use of file descriptor 3 in the above command is
> unnecessary. You could have just said:
>
> 	command 2>&1 >/dev/null
>
>>2. I am no awk expert (to say the least. I am not even an awk amateur.),
>>but it is outstanding at pulling out 'random' fields separated by
>>whitespace.
>>perhaps someone can enlighten me as to how I make it only print lines 7
>>and 8?
>
> 	command 2>&1 >/dev/null | awk '{ if (NR==7||NR==8) print $4; }'
>
> Tet
> --
> Gllug mailing list  -  Gllug at gllug.org.uk
> http://lists.gllug.org.uk/mailman/listinfo/gllug
>



That's almost what I wanted. In fact, the script I will use is:

command 2>&1 | awk '{ if (NR==7||NR==8) print $5; }' > output.txt

Since nothing is output on stdout, the redirection to /dev/null is
uneccessary; and since the lines in question start with spaces I'll take
field 5 (the formatting was lost on my original post).

Thanks everyone for your replies.

Gabriel.


-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list