Search code examples
ed

select noncontinuous lines in Ed


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


Solution

  • 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.