bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] gawk deal with file separator


From: Peng Yu
Subject: Re: [bug-gawk] gawk deal with file separator
Date: Fri, 13 Sep 2019 06:11:21 -0500

There are case when I need to do some preprocessing of files, but I want to
avoid temp file. I could do something like this.

awk -f file.awk <(process.sh f1.txt) <process f2.txt) <(printf ‘%s\n’
f{1,2}.txt)

Note that FILENAME won’t keep original filenames. But I need to know the
filenames. So I have to pass the filenames in the last ARGV, then I need to
process it and delete it in BEGIN. All of these are not convenient.

Alternatively, I could have a single stream if awk can support 3 level
progressing.

for f in f{1,2}.txt; do
printf “%s$FS” “$f”
process.sh “$f”
printf “$FS”
done | awk -f file.awk

The latter may end up less awk code if the 3 level support is designed
properly.

On Fri, Sep 13, 2019 at 2:20 AM <address@hidden> wrote:

> Peng Yu <address@hidden> wrote:
>
> > Hi,
> >
> > ASCII code has the FS (file separator) character. This means that
> > multiple files can be streamed one after another separated by FS. If
> > each file still is a TSV, this means that the input stream should have
> > three levels. But gawk only consider the input stream of two levels.
> > What is the best way to process the input with files separated by FS
> > in ASCII? Thanks.
> >
> > --
> > Regards,
> > Peng
>
> I really don't understand what you're trying to do or why you
> want to separate files by FS.
>
> Awk already gives you the tools to know when a file boundary
> has been crossed. Read the manual to learn about FNR and FILENAME.
> Additionally, gawk gives you BEGINFILE and ENDFILE patterns.
>
> I see no need to add special handling to gawk for the ASCII FS character;
> it's not used for that purpose in any modern (or even ancient) system
> that  I know of.
>
> Nor do I even know *how* I'd add such support.
>
> Arnold
>
-- 
Regards,
Peng


reply via email to

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