I have in a directory /home/files/ some files that all have the same extension .txt.For example1.txt2.txt3.txt4.txt5.txttest.txtThese files are all the same in data format but the data are different.All these files have at least the following line insideframes=[number here]This line appears multiple times in a file so i need to get the value of frames= that appears last in the file.And as i stated i want to get that line, from all the above files that match the extension .txt in a directory (no need for recursive).Is there any single bash command to do that? EDITExpected output:1.txt=50002.txt=1233.txt=34524.txt=1115.txt=958test.txt=1231
Fastest way to read last line within pattern of multiple files with the same extension
command line;files;text processing;scripting
With find + grep:find . -name '*.txt' -exec sh -c 'grep -HPo frames=\K.* $0 | tail -n1' {} \;And with shell for loop + grep in similar fashion:for file in *.txt; do grep -HPo 'frames=\K.*' $file | tail -n1; done