Building Bash Muscle (10)

In the 10th “Building Bash Muscle” series, I’m going back to sed and introducing tail. There are times when you need to read a big log file. I will peek at /var/log/syslog

The whole big log file should not be read into memory for an obvious reason. sed can be used to read part of the big file. Let’s read the 100th line of syslog with sed.

$ sed -n '100 p' /var/log/syslog

You can use the following command to read from 100th to 110th line.

$ sed -n '100,110 p' /var/log/syslog

You probably would not know which line to read but the practical situation would be you want to read the last 20 lines of the log file. You can use tail to accomplish it.

$ tail -n 20 /var/log/syslog

You can, of course, grep the result of the tail and narrow down the result further for analysis.

To recap, sed and tail can be used to get a part of big files.

Leave a Reply

Your email address will not be published.