I have a file with many lines but I can summarise my requirements like below:
<DT><A HREF="http://127.0.0.1:1234/ABCDE/wp-admin/index.cfm?event&msg=secure&fr=sp">Wonderland(Site 3)</A>
<DT><A HREF="http://127.0.0.1:5678/FGHIJ/wp-admin/index.cfm?event&msg=secure&fr=sp">abc (test)</A>
--
<DT><A HREF="http://127.0.0.1:1234/ABCDE/wp-admin/index.cfm?event&msg=secure&fr=sp">Wonderland(Site 3)</A>
<DT><A HREF="http://127.0.0.1:8303/CFIDE/administrator/index.cfm?event&msg=secure&fr=sp">xyz (Prod)</A>
--
<DT><A HREF="http://127.0.0.1:1234/ABCDE/wp-admin/index.cfm?event&msg=secure&fr=sp">Wonderland(Site 3)</A>
<DT><A HREF="http://127.0.0.1:8303/CFIDE/administrator/index.cfm?event&msg=secure&fr=sp">lmn (Prod)</A>
I have to insert a new line after first occurrence of:
<DT><A HREF="http://127.0.0.1:1234/ABCDE/wp-admin/index.cfm?event&msg=secure&fr=sp">Wonderland(Site 3)</A>
similar to it e.g.
<DT><A HREF="http://127.0.0.1:2323/xnmp/wp-admin/index.cfm?event&msg=secure&fr=sp">NewSite(Site 4)</A>
insert a new line after second occurrence with another variable line similar to above and so does after third line match.
I have tried something like this with various combinations but it is not working:
input1='<DT><A HREF="http://127.0.0.1:1234/ABCDE/wp-admin/index.cfm?event&msg=secure&fr=sp">Wonderland(Site 3)</A>
output1='<DT><A HREF="http://127.0.0.1:2323/xnmp/wp-admin/index.cfm?event&msg=secure&fr=sp">NewSite(Site 4)</A>'
output2='<DT><A HREF="http://127.0.0.1:2324/xnmp/wp-admin/index.cfm?event&msg=secure&fr=sp">NewSite(Site 4)</A>'
output3='<DT><A HREF="http://127.0.0.1:2124/xnmp/wp-admin/index.cfm?event&msg=secure&fr=sp">NewSite(Site 4)</A>'
gawk -i inplace -v in2="$input1" -v voutput1="$output1" '/in2/{c++;if(c==1){sub(in2,in2 "\n" voutput3);c=0}}1' a ; where a is my file name
I am able to replace all using sed but not individually. Working one which replaces all:
sed -i.bak "s#$input1#$input1\n\t\t$output1#" a
Expected output:
<DT><A HREF="http://127.0.0.1:1234/ABCDE/wp-admin/index.cfm?event&msg=secure&fr=sp">Wonderland(Site 3)</A>
<DT><A HREF="http://127.0.0.1:2323/xnmp/wp-admin/index.cfm?event&msg=secure&fr=sp">NewSite(Site 4)</A>
<DT><A HREF="http://127.0.0.1:5678/FGHIJ/wp-admin/index.cfm?event&msg=secure&fr=sp">abc (test)</A>
--
<DT><A HREF="http://127.0.0.1:1234/ABCDE/wp-admin/index.cfm?event&msg=secure&fr=sp">Wonderland(Site 3)</A>
<DT><A HREF="http://127.0.0.1:2324/xnmp/wp-admin/index.cfm?event&msg=secure&fr=sp">NewSite(Site 4)</A>
<DT><A HREF="http://127.0.0.1:8303/CFIDE/administrator/index.cfm?event&msg=secure&fr=sp">xyz (Prod)</A>
--
<DT><A HREF="http://127.0.0.1:1234/ABCDE/wp-admin/index.cfm?event&msg=secure&fr=sp">Wonderland(Site 3)</A>
<DT><A HREF="http://127.0.0.1:2124/xnmp/wp-admin/index.cfm?event&msg=secure&fr=sp">NewSite(Site 4)</A>
<DT><A HREF="http://127.0.0.1:8303/CFIDE/administrator/index.cfm?event&msg=secure&fr=sp">lmn (Prod)</A>