![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Replace the file using sed | senthil_is | Shell Programming and Scripting | 5 | 11-20-2008 07:58 AM |
| replace words in file based on another file | kinmak | Shell Programming and Scripting | 9 | 05-07-2008 05:06 AM |
| Replace word in a file | sasiharitha | UNIX for Dummies Questions & Answers | 3 | 12-05-2007 01:11 AM |
| serach and replace file name in the path in a remote xml file | kiranreddy1215 | Shell Programming and Scripting | 1 | 11-12-2007 11:31 AM |
| Replace a Value in File | lesstjm | Shell Programming and Scripting | 5 | 05-16-2007 01:20 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
replace nth value in xml file
Hi all,
I have application.xml file with following content <dependency> <groupId>fr.orange.portail.ear</groupId> <artifactId>_AdminServicesEAR</artifactId> <version>1.0.0-20080521.085352-1</version> <type>ear</type> </dependency> <dependency> <groupId>fr.orange.portail.ear</groupId> <artifactId>_AdminServicesEAR</artifactId> <version>1.0.0-20080521.085352-1</version> <type>ear</type> </dependency> <dependency> <groupId>fr.orange.portail.ear</groupId> <artifactId>_AdminServicesEAR</artifactId> <version>1.0.0-20080521.085352-1</version> <type>ear</type> </dependency> I want to replace nth <type> tag value (ie: ear) with "OK" using sed or awk.... i tried something like this for replacing the first occurance ... but not working . ![]() cat application.xml | awk '/\<type\>\(.*\)\<\/type\>/{n+=1}{if (n==1){gensub(/\<type\>\(.*\)\</type\>/,"OK",$0)};print }' Can any one please tell the correct syntax of this ??? Thanks and Regards, Subin |
|
||||
|
Code:
awk '/<type>.*<\/type>/{n+=1; if(n==2){gsub(/<type>.*<\/type>/,"OK",$0)}}1' application.xml
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|