Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: FILENAME ne...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 4 Topic 2173 of 2241
Post > Topic >>

Re: FILENAME never gets a value when running gawk from a batch file

by Janis <janis_papanagnou@[EMAIL PROTECTED] > Feb 29, 2008 at 12:43 AM

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 == 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




 4 Posts in Topic:
FILENAME never gets a value when running gawk from a batch file
di98mase <di98mase@[EM  2008-02-29 00:28:52 
Re: FILENAME never gets a value when running gawk from a batch f
Janis <janis_papanagno  2008-02-29 00:43:41 
Re: FILENAME never gets a value when running gawk from a batch f
di98mase <di98mase@[EM  2008-02-29 01:27:55 
Re: FILENAME never gets a value when running gawk from a batch f
Ed Morton <morton@[EMA  2008-02-29 07:03:27 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat May 17 6:24:12 CDT 2008.