sed Address and address range Specific range of lines


Example

$ cat ip.txt 
address
range
substitution
pattern
sample
  • Range specified is inclusive of those line numbers

    $ sed -n '2,4p' ip.txt 
    range
    substitution
    pattern
    
  • $ can be used to specify last line. Space can be used between address and command for clarity

    $ sed -n '3,$ s/[aeiou]//gp' ip.txt 
    sbstttn
    pttrn
    smpl
    

GNU sed
  • ith line to i+jth line

    $ sed '2,+2d' ip.txt 
    address
    sample
    
  • ith line and i+j, i+2j, i+3j, etc.

    $ sed -n '1~2p' ip.txt 
    address
    substitution
    sample