We can use tail command to get the last 'n' numbers from the file and the output of the tail command can be redirected to another file.This command is helpful when we have large files in the server and we cannot open it in text editor.Below command extract the last 1000 lines from catalina.out and this will be stored in log.txt file.
tail -1000 /usr/catalina.out >log.txt
This redirecting the output to a file can be used for grep command also as below. We can search a specified string in a file and redirect this output to a file
grep "teststring" /usr/catalina.out >log.txt