The following programs, which list the files in the current directory, work on GNU awk, but on One True Awk™ they only list the first found file (i.e., the first record). (Run them on a directory with more than one files)
#!/usr/bin/awk -f
function ls(dir, i, n, s, a, cmd) {
cmd = "find \"" dir "\" -mindepth 1 -maxdepth 1 -print0"
while ((cmd | getline s) > 0) {
a[++n] = s
}
close(cmd)
printf "%d file%s\n", n, ((n > 1) ? "s" : "")
for (i = 1; i <= n; i++) {
printf "%s\n", a[i]
}
}
BEGIN {
RS="\0"
ls(".")
}
This awk uses C strings internally. RS="\0" is the same as saying RS="". That's not going to change. If you need NUL as a separator, you have to use gawk.
The following programs, which list the files in the current directory, work on GNU awk, but on One True Awk™ they only list the first found file (i.e., the first record). (Run them on a directory with more than one files)