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: Andrew J. Schorr
Subject: Re: How to continue upon encountering nonexistent input files?
Date: Sat, 26 Feb 2022 21:00:50 -0500
User-agent: Mutt/1.5.21 (2010-09-15)

In theory, yes. You could write a gawk shared library extension
that could automatically decompress files:

https://www.gnu.org/software/gawk/manual/html_node/Input-Parsers.html

I'm not aware of anyone's having written such an extension yet.

Regards,
Andy

On Fri, Feb 25, 2022 at 09:39:50PM -0600, Peng Yu wrote:
> 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



reply via email to

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