[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: |
Fri, 25 Feb 2022 21:39:50 -0600 |
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