[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] gawk deal with file separator
From: |
Andrew J. Schorr |
Subject: |
Re: [bug-gawk] gawk deal with file separator |
Date: |
Fri, 13 Sep 2019 09:29:31 -0400 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
On Fri, Sep 13, 2019 at 06:11:21AM -0500, Peng Yu wrote:
> 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 you can run "process.sh" from inside awk using a command
pipeline. One possible approach is:
echo f1.txt f2.txt | gawk '
{
for (i = 1; i <= NF; i++) {
cmd = ("process.sh " $i)
# need to getline into a variable to avoid stomping on $n
while ((cmd | getline x) > 0) {
split(x, f)
# do your awk processing
}
close(cmd)
}
}'
Or perhaps more simply:
echo f1.txt f2.txt | gawk -v "RS=[[:space:]]+" '
{
cmd = ("process.sh " $0)
while ((cmd | getline) > 0) {
# do your awk processing
}
close(cmd)
}'
Regards,
Andy