Script to search every file in a directory and print last few lines

Hi everyone,

I need to write a script to search a directory, output the name of a file to an ouput file and print the last few lines of the files to the output file such that I would have something like this:

FILE1:
LINE
LINE 
LINE

FILE2:
LINE 
LINE
LINE

FILE3:
LINE
LINE 
LINE

Any ideas?

Hi,

Did you mean like this ?
I have a few files and each file has 5 lines for example.

find . -type f -print -exec tail -3 {} \;

Gives output:

To add a blank line between them, you could add another -exec clause to the find like this:-

find . -type f -print -exec tail -3 {} \; -exec echo \;

If you want file names to have a trailing colon : then it becomes a little more convoluted:-

find . -type f -exec echo "{}:" \; -exec tail -3 {} \; -exec echo \;

I hope that this helps,
Robin