Printing The Last 50 Lines Of A File

Having completed the coding of my BTP, I had to test the program. I wrote down a simple C program to do this and generate the outputs in log files in a specified folder. However, I messed it up big time. The actions included creating temporary files, catenating them and then moving them. I did it horribly wrong and ended up with lots of garbage in each log file. Only the last 50 lines of each file were the results, rest garbage.

I needed a way to retain the last 50 lines of each file and discard the rest. This is when I stumbled across the tail command. It does exactly this ! All you have to do call tail -50 <filename> for each of the files. Sweet !

A simple recursive loop, calling the tail command for each file, and yay I am done with my work. Now it is the time to analyse the results.

You might also like to read

0 Response to “Printing The Last 50 Lines Of A File”


  • No Comments

Leave a Reply

Comment moderation is enabled. Your comment may take some time to appear.




Theme Tweaker by Unreal