select noncontinuous lines in Ed

95 views Asked by At

if 3,5p prints lines 3, 4, and 5, how would one print, say, lines 4 AND 7, but not 5 and 6?

Have tried:

3 5 p prints line 8

3p5p breaks as well

1

There are 1 answers

0
Gumnos On BEST ANSWER

ed doesn't generally let you manipulate disjoint lines like this so you'd normally just do

4p
this is line 4
7p
this is line 7

However, ed does allow for a command-list within the context of a g// command, so if you really do need all the output in one response, you can hack it with

1g/^/4p\
7p
this is line 4
this is line 7

It's ugly, it's a hack, and it's inconvenient to type. But if you really do need all the output in one pass, this will do it.