Unix /Linux Command to display first n lines and last n lines of a files

If you are new to dark world of penguins where command line matters a lot, these two commands are going to be very handy to you

Read first n lines from a files :

head –10  install.log

This command will display first 10 lines of install.log files. In a similar manner, if you want to read a file from bottom, you can use tail command.

Read last n lines from a files

tail –5 install.log

tail command will output 5 lines from the bottom of install.log file.

Both commands can also be used at the same time to get some more interesting output. Lets say, I want to read 3 lines starting from 100. This can be interpreted as below command sequence

head –100 | nl | tail –3

This will result output similar in the stated problem. nl parameter in the command is used to print lines numbers, this can be omitted if you don’t want them.

0 Comments:

Post a Comment