Extract part of log file using less and sed

Sometimes when using less to view a log file, seem to need a little extra than just a screen full and the copy command just does not work well.  You can use the following two commands in combination to grab line numbers and then extract just those lines.

# Use this to get the line numbers
$ less -N hal-guest-server.log
# Use sed to extract that range to your home directory, notice the “little” p at the end of second line number
$ sed -n -e 32865,32966p hal-guest-server.log > ~/log-excerpt.txt

Leave a Reply