If you just want to insert a new line after pattern2 then this would work -
sed '/pattern2/s/$/\n/' file
[jaypal:~/Temp] cat file
some text
some text
some text pattern1
some text p
some text p
some text p
some text pattern2
some text
some text
[jaypal:~/Temp] sed '/pattern2/s/$/\n/' file
some text
some text
some text pattern1
some text p
some text p
some text p
some text pattern2
some text
some text
i\
is for inserting. It would insert before
an address. If you need a new line you would use \a
which is append
.
[jaypal:~/Temp] sed '/pattern2/ a\
' file
some text
some text
some text pattern1
some text p
some text p
some text p
some text pattern2
some text
some text
If you want to add a new line after your /pattern2/ and view lines between them, then may be you can do something like this -
[jaypal:~/Temp] sed -e '/pattern2/G' -ne '/pattern1/,/pattern2/p' file
some text pattern1
some text p
some text p
some text p
some text pattern2
[jaypal:~/Temp]
Similar solution in awk
-
[jaypal:~/Temp] cat file
some text
some text
some text pattern1
some text p
some text p
some text p
some text pattern2
some text
some text
[jaypal:~/Temp] awk '/pattern1/,/pattern2/ END{print ""}' file
some text pattern1
some text p
some text p
some text p
some text pattern2
[jaypal:~/Temp]