2

In ed one can delete a line number by typing its address followed by the delete command, as in 1d. To delete a range of lines, one uses the comma, as in 1,4d. One can also delete lines with specific content as in g/Ted/d. Is there a way to specify the deletion of non-sequential lines in a single command? I.e. let's say I wanted to delete lines 1 and 3 and 8 at one time without typing:

1d
3d
8d
1
  • you can use a heredoc and include the lines you want to delete. It's one single command, and it accepts whatever input you like. To spec: Using ed and in one single command.
    – runlevel0
    Commented May 3 at 15:16

1 Answer 1

1

Not with ed (an editor from the 60s), no. But with ex (in case you're ready to venture into the 70s or later), or rather the vim implementation of ex (90s), you can do:

g/\v%1l|%3l|%8l/d

Where \%nl (simplified to %nl with \v) is a regexp operator that matches wherever the current line is the nth.

Note that with the approach that runs 1d, 3d, 8d in sequence, after 1d what used to be the third line is now the second, so you'd end up deleting the 1st, 4th and 10th lines. You don't have that problem if you start from the end: 8d, 3d, 1d.

3

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .