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

Deleting – the d command

The d command is used to delete lines. After sed copies a line from a file and puts it into a pattern buffer, it processes commands on that line, and, finally, displays the contents of the pattern buffer on screen. When the d command is issued, the line currently in the pattern buffer is removed and not displayed, as follows:

    $ cat country.txt
    Country     Capital     ISD Code
    USA         Washington  1
    China       Beijing     86
    Japan       Tokyo       81
    India       Delhi       91
    $ sed '3d' country.txt
  

The output is as follows:

    Country      Capital    ISD Code
    USA          Washington 1
    Japan        Tokyo           81
    India        Delhi       91
  

Here is the explanation.

The output will contain all the lines except the third line. The third line is deleted by the following command:

    $ sed '3,$d' country.txt ...
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