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