[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 11:47:23 -0500 |
process.sh could be more complex than just a simple script. It could
be a bash function, a pipeline, etc. Therefore, it may not be always a
good idea to put it into awk code.
> 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,
Peng