Skip to Content
Learning Linux Shell Scripting - Second Edition
book

Learning Linux Shell Scripting - Second Edition

by Ganesh Sanjiv Naik
May 2018
Beginner
332 pages
7h 28m
English
Packt Publishing
Content preview from Learning Linux Shell Scripting - Second Edition

Head and tail

For testing the next few commands, we will need a file with a sequence of numbers from 1 to 100. For this, use the following command:

    $ seq 100 > numbers.txt

The preceding command creates a file with the numbers 1 to 100 on separate lines. The following example shows the usage of the head command:

    $ head numbers.txt      // will display 10 lines
    $ head -3 numbers.txt   // will show first 3 lines
    $ head +5 numbers.txt   // will show from line 5. In few shells this command may not work

The following example shows the usage of the tail command:

    $ tail numbers.txt      // will display last 10 lines
    $ tail -5  numbers.txt        // will show last 5 lines
    $ tail +15 numbers.txt  // will show from line 15 onwards. In few shells this may not work

To print ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Linux Shell Scripting

Learning Linux Shell Scripting

Ganesh Sanjiv Naik
Linux Shell Scripting Cookbook - Third Edition

Linux Shell Scripting Cookbook - Third Edition

Clif Flynt, Sarath Lakshman, Shantanu Tushar

Publisher Resources

ISBN: 9781788993197Supplemental Content