Find a string and place two blank lines

Hi friends,

I am looking for a line to find a particular string in my file and once found then replace with 2-3 blank lines before the string

Example:

 
aaa 11 bbb
1
2
3
 
aaa 22 bbb
4
5
6

Output

 
 
aaa 11 bbb
1
2
3
 
 
 
aaa 22 bbb
4
5
6

Thanks in advance

Is this what you are after?

$ cat file
aaa 11 bbb
1
2
3

aaa 22 bbb
4
5
6

aaa 33 bbb
1
2
3
$ awk -v RS="" -v ORS="\n\n" '/aaa 22 bbb/{print "\n\n" $0;next}{print}' file
aaa 11 bbb
1
2
3



aaa 22 bbb
4
5
6

aaa 33 bbb
1
2
3

I am getting below error:

omcadmin>awk -v RS="" -v ORS="\n\n" '/aaa 22 bbb/{print "\n\n" $0;next}{print}' file
awk: syntax error near line 1
awk: bailing out near line 1

---------- Post updated at 05:59 PM ---------- Previous update was at 05:55 PM ----------

Sorry that worked..
But i need for all lines starting with aaa and ending with bbb
I tried this but not working

nawk -v RS="" -v ORS="\n\n" '/^aaa.*bbb$/{print "\n\n" $0;next}{print}' file

Tested with GNUawk, original-awk and mawk. All successfully.

Try:

awk 'BEGIN{RS="";ORS="\n\n"} /aaa 22 bbb/{print "\n\n" $0;next}{print}' file

---------- Post updated at 02:37 PM ---------- Previous update was at 02:33 PM ----------

Ok. Then, simply try

awk '/^aaa.+bbb$/{print "\n\n" $0;next}{print}' file

Thanks a LOT :slight_smile: