like i have file like
abc
123
pqr
bbbb
ttttttttt
t
tttt
------------------
i want to insert "class" after pqr and t lines
please suggest me.
like i have file like
abc
123
pqr
bbbb
ttttttttt
t
tttt
------------------
i want to insert "class" after pqr and t lines
please suggest me.
Try:
sed -e '/pqr/G' -e '/^t$/G' < filename | sed 's/^$/class/g'
THANKS FOR REPLY
but it also insert row at last also, and please tell If I want to insert row after 2 rows of desire row
like:
i/p:
pqr
abcv
dddd
33333
--------------
o/p insert "best" after 2 rows of pqr
pqr
abcv
dddd
best
33333
----------------------
pls try below sed command
sed -n '/pqr/ !{
p
}
/pqr/ {
p
n
p
n
p
i\
best
}' filename
below is the same with above ( insert line after match)
sed '/pqr/a\
------------------
/^t$/a\
------------------
' filename
below is the slightly different ( insert line before match line)
sed '/pqr/i\
------------------
/^t$/i\
------------------
' filename
use SED i option.