How to get the list of filenames which have last line (or line on position X) matching certain pattern?
We are looking for oneliner.
How to get the list of filenames which have last line (or line on position X) matching certain pattern?
We are looking for oneliner.
awk '/pattern/ {last_matching_line = FNR} (FNR != NR && FNR==1) {if (last_FNR == last_matching_line) {print last_filename}} {last_FNR = FNR; last_filename = FILENAME} END {if (FNR == last_matching_line) {print FILENAME}}' file1 file2...
last_matching_line
by FNR
.FNR==1
) or is processing the last file (END
).FILENAME
.For the line on position X question, it is easier because there is only one case to check: FNR == X
.