help-gawk
[Top][All Lists]
Advanced

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

Re: How to continue upon encountering nonexistent input files?


From: Peng Yu
Subject: Re: How to continue upon encountering nonexistent input files?
Date: Sat, 26 Feb 2022 17:17:39 -0600

I want something equivalent to this, but I don't want to use unnamed
pipe in bash. I'd like to have a way let awk use a pipe of zcat within
awk to be able to read gz files in an uncompressed way without dumping
the output to a file first.

awk -e '{ print }' x.txt <(zcat y.txt.gz)

On 2/26/22, Antonio Giovanni Colombo <azc100@gmail.com> wrote:
> Hi Peng,
>
> It depends on what you want to do. Of course Gawk can't really do
> anything with ".gz" files, which are just a bunch of  random chars.
> But at the BEGINFILE level, if you see a ".gz" file-name you can invoke
> "system("gunzip" FILENAME)" or similar, and then "getline" the output from
> gunzip. Not sure it is what you want to do.
>
> All the best, Antonio
>
>
> Il giorno sab 26 feb 2022 alle ore 04:39 Peng Yu <pengyu.ut@gmail.com> ha
> scritto:
>
>> Is there a way to make this works for gz files without using external
>> pipes?
>>
>> For example, I don't want to use the following.
>> awk -e '{ print }' x.txt <(zcat y.txt.gz)
>>
>> Instead, I want to do something like this.
>>
>> awk -e 'some awk code to process each input file with BEGINFILE' x.txt
>> y.txt.gz
>>
>> Is this possible?
>>
>>
>> On 2/25/22, Andrew J. Schorr <aschorr@telemetry-investments.com> wrote:
>> > On Fri, Feb 25, 2022 at 01:23:10PM -0600, Peng Yu wrote:
>> >> $ awk -e '{ print }' x.txt <(builtin printf '%s\n' {1..3})awk: fatal:
>> >> cannot open file `x.txt' for reading: No such file or directory
>> >>
>> >> As shown above, the above command stops when a nonexistent file is
>> >> encountered. Is there a way to let awk keep on proceeding (but allows
>> >> a way to handle the error in the awk code, e.g., print a customized
>> >> error message)?
>> >
>> > Please use a BEGINFILE rule, described in the docs:
>> >
>> >
>> https://www.gnu.org/software/gawk/manual/html_node/BEGINFILE_002fENDFILE.html
>> >
>> > Regards,
>> > Andy
>> >
>>
>>
>> --
>> Regards,
>> Peng
>>
>>
>
> --
>    /||\    | Antonio Colombo
>   / || \   |  azc100@gmail.com
>  /  ()  \  | antonio@geekcorp.com
> (___||___) |   azc10@yahoo.com
>


-- 
Regards,
Peng



reply via email to

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