0

I have files named memOutput.X where X ranges from 0 to 47 in a directory. I want to see the line with the last occurrence of VmData in all these files. I can run

grep VmData memOutput.0 | tail -1

to get the last match from one file but not sure how to do it for a range of files. Also, grep VmData memOutput.* | tail -1 displayed only the last match from file memOutput.47. Is there an alternative to grep?

Thanks.

nac001
  • 103
  • 4

1 Answers1

1

Use a loop?

for file in memOutput.*; do
    grep -H VmData "${file}" | tail -n 1
done

Or if you want a one-liner:

for file in memOutput.*; do grep -H VmData "${file}" | tail -n 1;done 
Sirch
  • 5,785
  • 4
  • 20
  • 36