Skip to Content
sed & awk, 2nd Edition
book

sed & awk, 2nd Edition

by Dale Dougherty, Arnold Robbins
March 1997
Intermediate to advanced
432 pages
11h 31m
English
O'Reilly Media, Inc.
Content preview from sed & awk, 2nd Edition

Delete

We previously showed examples of the delete command (d). It takes an address and deletes the contents of the pattern space if the line matches the address.

The delete command is also a command that can change the flow of control in a script. That is because once it is executed, no further commands are executed on the “empty” pattern space.[4] The delete command causes a new line of input to be read and a new pass on the editing script to begin from the top. (In this behavior, it is the same as the next command, which you’ll encounter later in this chapter.)

The important thing to remember is: if the line matches the address, the entire line is deleted, not just the portion of the line that is matched. (To delete a portion of a line, use the substitute command and specify an empty replacement.) In the previous chapter, we showed a command to delete blank lines:

/^$/d

Another use of the delete command could be to strip out certain troff requests, such as those that add spacing, break the page, and turn fill mode off and on:

/^\.sp/d
/^\.bp/d
/^\.nf/d
/^\.fi/d

These commands delete an entire line. For instance, the first command will delete the line “.sp 1” or “.sp .03v”.

The delete command can be used to delete a range of lines. In the previous chapter, there is an example of deleting all tables from a file by deleting the lines between the .TS and .TE macros. There is also a delete command (D) used to delete a portion of a multiline pattern space. This advanced command is ...

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

The AWK Programming Language, 2nd Edition

The AWK Programming Language, 2nd Edition

Alfred V. Aho, Brian W. Kernighan, Peter J. Weinberger

Publisher Resources

ISBN: 1565922255Supplemental ContentErrata Page