learn_gnuawk icon indicating copy to clipboard operation
learn_gnuawk copied to clipboard

Q: 74/88 could have better input files

Open FabijanC opened this issue 1 year ago • 0 comments

It's also numerated as exercise 2) in https://learnbyexample.github.io/learn_gnuawk/multiple-file-input.html

For the input files sample.txt, secrets.txt, addr.txt and table.txt, display only the names of files that contain at or fun in the third field. Assume space as the field separator.

The expected solution is:

$ awk '$3 ~ /fun|at/{print FILENAME; nextfile}' sample.txt secrets.txt addr.txt table.txt

but it also works without nextfile.

Suggestion

Use a file which has multiple records containing at or fun in the third field, so that if you forget to use nextfile, the output is not matched due to a filename being printed more than once.

I would also add to the problem specification that the file name is expected to be printed once per file (if other criteria met).

FabijanC avatar Jun 05 '24 16:06 FabijanC