&10"
Hi all,
I've build a small gawk script that is intended to provide the user three outputs, all at the END block.
This is running in Linux.
Preferable, I'd like some non-specific gawk awk.
The script is invoked as:
find . -name '*.yml' | xargs awk -f script.awk
Schematics of the script:
do some stuff for some lines of each file
END {
do some stuff
print "title1"
for - some cycle
print "details"
print "title2"
for - another cycle
printf("%12s,%6s\n", k_arr[1], somefunc(k_arr[2])) | "sort -t -
k2,2"
print "title3"
for - third cycle
print detail
}
As it is, it prints all from first for cycle, the title of the second, the third cycle and only aftwerwards the detail of the second cycle.
As I have searched and understand, the sort is done after all of the printfs.
So, I thought of using file descriptors, to have the prints in order. Modified the printf line to:
printf("%12s,%6s\n", k_arr[1], somefunc(k_arr[2])) | "sort -t -k2,2 | cat>&10"
And adding below:
while ((getline < "/dev/fd/10") >0)
print $0
But get either, bad file descriptor or file descriptor not found.
What should be modified?
Another question, as some file descriptors are in use, how to find a file descriptor that is free to be used?
Thanks,
Luís Mendes
Hi all,
I've build a small gawk script that is intended to provide the user three >outputs, all at the END block.
This is running in Linux.
Preferable, I'd like some non-specific gawk awk.
The script is invoked as:
find . -name '*.yml' | xargs awk -f script.awk
Schematics of the script:
do some stuff for some lines of each file
In article <690c5dc2$0$665$14726298@news.sunsite.dk>,
Luis Mendes <luisXXXlupe@gmail.com> wrote:
Hi all,
I've build a small gawk script that is intended to provide the user three >> outputs, all at the END block.
This is running in Linux.
Preferable, I'd like some non-specific gawk awk.
The script is invoked as:
find . -name '*.yml' | xargs awk -f script.awk
Schematics of the script:
do some stuff for some lines of each file
I think Janis has the right idea here - which is that you have to close the sort command before it will generate any output. In your script, without
an explicit close(), the sort gets closed automatically when AWK exits,
which results in the output coming out then (after everything else has already been printed by the AWK script).
This is kind of the "first principle" of "sort" - the fact that it cannot generate any output until it is sure that it has read all the input. [...]
On 06.11.2025 18:17, Kenny McCormack wrote:
In article <690c5dc2$0$665$14726298@news.sunsite.dk>,
Luis Mendes <luisXXXlupe@gmail.com> wrote:
Hi all,
I've build a small gawk script that is intended to provide the user
three outputs, all at the END block.
This is running in Linux.
Preferable, I'd like some non-specific gawk awk.
The script is invoked as:
find . -name '*.yml' | xargs awk -f script.awk
Schematics of the script:
do some stuff for some lines of each file
I think Janis has the right idea here - which is that you have to close
the sort command before it will generate any output. In your script,
without an explicit close(), the sort gets closed automatically when
AWK exits, which results in the output coming out then (after
everything else has already been printed by the AWK script).
This is kind of the "first principle" of "sort" - the fact that it
cannot generate any output until it is sure that it has read all the
input. [...]
Just be aware that the effect can not only be seen with external
commands that wait for all input (like sort) but also for commands that
are able to immediately output its processed input; e.g. in
{ print | "cat -" }
END { print "END" }
if fed with, say, 'seq 10' you will first see the "END". Awk just cannot
know whether another output will subsequently get fed into that pipe, as
in
{ print | "cat -" }
END { print "END"
print "PS" | "cat -" }
so it has to wait until the program terminates unless explicitly closed.
So for a correct sequencing of the output in case where _external_
commands are triggered a close() seems mandatory.
The insight is, IMO, that the piped command string is acting like a
_handle_ (associated with some file descriptor), and if there's
somewhere in the program another such handle it's addressing the same channel; e.g. in this simple case
{ print | "sort -r" } { print | "sort -r" }
the printed output is processed by the identical "sort -r" command.
Whereas if your handle differs, as in
{ print | "sort -r" } { print | "sort -r" }
you'll get the output of two instances. - That's also one reason why
there should a variable be used instead of a literal string if you refer
to the identical command instance; it avoids typos that could change the operational semantics.
Janis
Hi all,
I've build a small gawk script that is intended to provide the user three outputs, all at the END block.
This is running in Linux.
Preferable, I'd like some non-specific gawk awk.
The script is invoked as:
find . -name '*.yml' | xargs awk -f script.awk
Schematics of the script:
do some stuff for some lines of each file
END {
do some stuff
print "title1"
for - some cycle
print "details"
print "title2"
for - another cycle
printf("%12s,%6s\n", k_arr[1], somefunc(k_arr[2])) | "sort -t - k2,2"
print "title3"
for - third cycle
print detail
}
As it is, it prints all from first for cycle, the title of the second, the third cycle and only aftwerwards the detail of the second cycle.
As I have searched and understand, the sort is done after all of the
printfs.
So, I thought of using file descriptors, to have the prints in order. Modified the printf line to:
printf("%12s,%6s\n", k_arr[1], somefunc(k_arr[2])) | "sort -t -k2,2 | cat>&10"
And adding below:
while ((getline < "/dev/fd/10") >0)
print $0
But get either, bad file descriptor or file descriptor not found.
What should be modified?
Another question, as some file descriptors are in use, how to find a file descriptor that is free to be used?
Thanks,
Luís Mendes
| Sysop: | DaiTengu |
|---|---|
| Location: | Appleton, WI |
| Users: | 1,089 |
| Nodes: | 10 (0 / 10) |
| Uptime: | 153:54:27 |
| Calls: | 13,921 |
| Calls today: | 2 |
| Files: | 187,021 |
| D/L today: |
3,760 files (944M bytes) |
| Messages: | 2,457,163 |