bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] Is there a way to get the current file number?


From: Peng Yu
Subject: Re: [bug-gawk] Is there a way to get the current file number?
Date: Tue, 9 Apr 2019 09:38:51 -0500

I missed it. I think that it is not named in the best way. It is used
in the same context as FILENAME, thus, FILEIND or FILEIDX may be a
better choice.

On 4/9/19, address@hidden <address@hidden> wrote:
> David's answer is clean and portable. There is also gawk's ARGIND
> variable. See the manual.
>
> Thanks,
>
> Arnold
>
> david kerns <address@hidden> wrote:
>
>> using your same example:
>> $ awk 'FNR==1 {filenumber++} { print FILENAME, filenumber, $0 }'
>> /tmp/1.txt
>> /tmp/1.txt /tmp/1.txt
>> /tmp/1.txt 1 1
>> /tmp/1.txt 2 1
>> /tmp/1.txt 3 1
>>
>>
>> On Wed, Apr 3, 2019 at 12:25 PM Peng Yu <address@hidden> wrote:
>>
>> > Hi,
>> >
>> > FILENAME only gives the filename. Is there a way to get the file
>> > number?
>> > Thanks.
>> >
>> > $ echo 1 > /tmp/1.txt
>> > $ awk -e '{ print FILENAME, $0 }' /tmp/1.txt  /tmp/1.txt
>> > /tmp/1.txt 1
>> > /tmp/1.txt 1
>> >
>> > --
>> > Regards,
>> > Peng
>> >
>> >
>


-- 
Regards,
Peng



reply via email to

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