[Solved] Inserting a line beginning with regex

I have been trying to insert a line after a regex but I can't do it. Here is the code I am using:

cat saved_doc 
SET type = type1 
SET type = STORE = y
/vol/san_e1
/vol/san_5
/vol/san_e9
/vol/san_e11
/vol/san_e12
/vol/san_e13
/vol/san_e14
/vol/san_e16
/vol/san_e17
/vol/san_e18
/vol/san_e19
/vol/san_e20
/vol/san_e23
/vol/san_e24
/vol/san_e26
/vol/san_e27
/vol/san_e28

What I have done is this:

cat saved_doc |gawk '{printf "NEW\n"; print}'

This makes the file look good except that I want NEW to be inserted starting after the line SET type = STORE = y only. Then the file should look like this:

SET type = type1 
SET type = STORE = y
NEW
/vol/san_e1
NEW
/vol/san_5
NEW
/vol/san_e9
NEW
/vol/san_e11
NEW
/vol/san_e12
NEW
/vol/san_e13
NEW
/vol/san_e14
NEW
/vol/san_e16
NEW
/vol/san_e17
NEW
/vol/san_e18
NEW
/vol/san_e19
NEW
/vol/san_e20
NEW
/vol/san_e23
NEW
/vol/san_e24
NEW
/vol/san_e26
NEW
/vol/san_e27

Anybody have an idea? Once I have this fixed, I can place it into the rest of the script but for now NEW starts at the first line of the file and goes to the end. I've tried sed, but that goes for specific lines and

NR %2 = 0 

but that captures even lines and so on.

Based on line number you could do:

awk 'NR>3{print "NEW"}1' infile

or on "STORE = y" string:

awk 'N{print "NEW"}/STORE = y/{N=1}1' infile
1 Like
awk 'NR>2{$0="NEW" RS $0}1' saved_doc
1 Like

This seemed simple, but I was trying to use sed which I have used most often and got close to but never found the correct awk solution.

Thanks to all!

Using sed :

sed '/STORE = y/,$ s/$/\nNEW/; $ s/\nNEW//' file

or

sed '/STORE = y/,$ {$ !s/$/\nNEW/}' file