On 29 Feb, 09:43, Janis <janis_papanag...@[EMAIL PROTECTED]
> wrote:
> On 29 Feb., 09:28, di98mase <di98m...@[EMAIL PROTECTED]
> wrote:
>
> > Hi all,
>
> > after a few minutes of studying the FILENAME variable I cant
> > understand why my simple program does not work. This is what I want to
> > achieve:
>
> > I have a batch file that looks like:
> > echo "************************ Extract all general statistics
> > ****************"
> > gawk -f statistics.awk <..\logs\%1 > ..\results\statistics.res
>
> You are asking your command shell to open a file and the shell
> connects the data stream to the standard input channel. While
> the shell knows about the file the awk program just sees data
> on stdin without knowledge whether the data comes from a file
> or whether it is the output of another process that is attached
> by a pipe.
>
>
>
>
>
>
>
> > I run this using the command:
> > process_stats.bat mylogfile.log
>
> > in my awk program I have tried to use this in my END statement (since
> > the filename does not have any value in before the BEGIN is processed:
>
> > END {
> > print "Filename processed:", FILENAME;
>
> > }
>
> > I also tried:
>
> > BEGIN {}
>
> > FNR =3D=3D 1 { print "Filename processed:",FILENAME }
> > :
> > :
> > But both examples with the same result "Filename processed:-".
>
> '-' is the convention to denote standard input.
>
>
>
> > I cant see why this should not work? Is it because I use a input
> > parameter to the batch file?
>
> To give programs (awk in this case) a chance to know about the
> filename you should pass the file names as arguments to awk...
>
> gawk -f statistics.awk ..\logs\%1 >..\results\statistics.res
>
> (Mind the missing '<'.) If you want to process multiple files
> provide a list of file names...
>
> gawk -f statistics.awk ..\logs\file1 ..\logs\file2 ..\logs\file3
>
> Janis
>
>
>
>
>
> > /di98mase- D=F6lj citerad text -
>
> - Visa citerad text -- D=F6lj citerad text -
>
> - Visa citerad text -
It works! just by removing the '<' it works! Nice!
Is there drawbacks/benefits passing the input file as an arguement vs
using a stream?
Thanks Janis!
/di98mase


|