Using sed head tail and cat on large text files

From Free Knowledge Base- The DUCK Project: information for everyone
Jump to: navigation, search
sed -n -e Xp -e Yp FILENAME
   sed : sed command, which will print all the lines by default.
   -n : Suppresses output.
   -e CMD : Command to be executed
   Xp: Print line number X
   Yp: Print line number Y
   FILENAME : name of the file to be processed.
sed -n -e 120p -e 145p -e 1050p /var/log/syslog
sed -n M,Np FILENAME
sed -n 101,110p /var/log/cron

displays only first 15 lines of /var/log/maillog file.

head -n 15 /var/log/maillog

display all the lines of the /var/log/secure except the last 250 lines.

head -n -250 /var/log/secure
tail -n 50 /var/log/messages

ignores the 1st four lines of the /etc/xinetd.conf, which contains only the comments.

tail -n +5 /etc/xinetd.conf

follow live

tail -f /var/log/syslog

display line numbers 101 – 110 of /var/log/anaconda.log file

cat /var/log/anaconda.log | tail -n +101 | head -n 10

See the following web site for details on these examples:

reference: http://www.thegeekstuff.com/2009/08/10-awesome-examples-for-viewing-huge-log-files-in-unix/