Skip to content

Q: 74/88 could have better input files #11

Closed
@FabijanC

Description

@FabijanC

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions