more a-d.txt1
<a-dets>
<a-serv>
<aserv>mymac14,mymac15:MYAPP:mydom:/web/domain/mydom/config
<NMGR>:MYAPP:/web/bea_apps/perf/NMGR/NMGR1034
<a-rep-string>
11.12.10.01=192.10.00.26
10.20.18.10=192.10.00.27
</a-rep-string>
</a-serv>
<w-serv>
<wserv>mywmac3,mywmac4:MYAPP:dev.MYAPP01.mycomp.com:/web/apache/2.4.10/https-MYAPP01/conf
<web-replace-string>
</web-replace-string>
</w-serv>
</a-dets>
I need to save the contents of first occurrence of <a-dets></a-dets> in app1.tmp and the next occurrence if found in the app2.tmp and so on.
It used to work on my previous Operating System using the below command.
awk '/<a-dets>/{A=1;++i} A{print >> ("app"i".tmp")} /<\/a-dets>/{A=0} ' a-d.txt1
But it does not work on my current OS i.e Linux mymac 2.6.18-416.el5 #1 SMP Wed Oct 26 12:04:18 EDT 2016 x86_64 x86_64 x86_64 GNU/Linux
Question:
-
Can you please help explain what went wrong and why is the awk not extracting the data between the tags ? Is that acceptable or fault in the command ?
-
Can i use
sed
instead ofawk
to achieve the same as awk has too many flavors to deal with and i want this to run on most OS.