-
Couldn't load subscription status.
- Fork 82
Description
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.txtandtable.txt, display only the names of files that containatorfunin 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).