sed Address and address range Specific range of lines

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

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
    


Got any sed Question?