piped to awk: how to print vars outside of line-in loop



Hi all,

I have been tinkering with a shell script that takes the output from a
program and pipes it to awk to extract certain items and format them
nicely. So far I have this:

[...]
mplayer -vo null -ao null -frames 0 -identify 2> /dev/null $VideoFile |
awk -F = '
/ID_/ {
if (index($0,"DEMUXER") > 1) Container = $2
else if (index($0,"CLIP_INFO_VALUE0") > 1) Encoder = $2
[...]
}

{
print "Encoder is: " Encoder
print "Container is:" Container
}'

This works, except of course the "print" statement is repeated for each
line piped to awk (at least that is what I think is happening). How do
I print the variables assigned in the first {} just once?

Also, is there any way of accessing the awk variables in the subsequent
lines of the shell script?

I am new to awk and your forbearance is appreciated.

Thanks.

--
Colin Brace
Amsterdam

.



Relevant Pages

  • Re: piped to awk: how to print vars outside of line-in loop
    ... I have been tinkering with a shell script that takes the output from a ... program and pipes it to awk to extract certain items and format them ... print "Encoder is: " Encoder ... print "Container is:" Container ...
    (comp.unix.shell)
  • Re: Multi line match and uniq.
    ... >(Generated by a java process sending the error to Stnd error and std ... And a shell script sending both to a file.) ... facility 'awk' has for dealing with NEWLINE delimited records (setting ...
    (comp.unix.shell)
  • Re: Awk and shell variables
    ... The fact is that i'm using the awk command to do that (i think its the ... one for) but i need to use awk variables in my shell script. ... echo "Jour max: "$JOURMAX ...
    (comp.unix.shell)
  • Re: piped to awk: how to print vars outside of line-in loop
    ... I have been tinkering with a shell script that takes the output from a ... program and pipes it to awk to extract certain items and format them ... print "Encoder is: " Encoder ... print "Container is:" Container ...
    (comp.unix.shell)
  • Re: Awk and shell variables
    ... The fact is that i'm using the awk command to do that (i think its the ... one for) but i need to use awk variables in my shell script. ... The "echo" command print 0 and it should print 9 ...
    (comp.unix.shell)