help-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: is the name of the file being interpreted available?


From: Ed Morton
Subject: Re: is the name of the file being interpreted available?
Date: Sun, 19 Jun 2022 10:50:01 -0500
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0

Thanks but I'm looking for the name of the file that contains the awk SCRIPT, not the name of the input file that the awk script is reading. In your example I'd expect that string to be "-" or "".

    Ed.

On 6/19/2022 10:46 AM, Antonio Giovanni Colombo wrote:
Hi,

As soon as you start actually processing a file (i.e. AFTER "BEGIN" time), you have the FILENAME variable that holds the name of the file currently being processed.

C:\>echo ciao|gawk " NR==1 { print FILENAME } "
-
C:\>gawk " NR==1 { print FILENAME } " alldirs.txt
alldirs.txt
C:\>

If you process more than one file, FILENAME will change at each new file.

Hope it helps, Antonio


Il giorno dom 19 giu 2022 alle ore 17:28 Ed Morton <mortoneccc@comcast.net> ha scritto:

    I just realised that while shell has $0 to hold the name of the file
    containing the script being interpreted, I don't know if that same
    information is available in any builtin variable in awk. Obviously I
    could write:

         awk -v script='/foo/bar/script.awk' -f '/foo/bar/script.awk'
    input

    or similar but is there any way to get that '/foo/bar/script.awk'
    info
    inside the awk script without any manual intervention so I can
    just write:

         BEGIN { "we are running", foo }

    for some value of `foo` inside the script to output:

         we are running /foo/bar/script.awk

    Regards,

         Ed.



--
 /||\    | Antonio Colombo
  / || \   | azc100@gmail.com
 / ()  \  | antonio@geekcorp.com
(___||___) | azc10@yahoo.com


reply via email to

[Prev in Thread] Current Thread [Next in Thread]