The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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
append data to file fletcher UNIX for Dummies Questions & Answers 1 02-07-2009 07:08 AM
Using awk (or whatever) to pull and append data in a new file Milano_EH3 UNIX for Dummies Questions & Answers 6 01-27-2009 05:10 PM
How to parse the specific data from the file MuthuAlagappan UNIX for Dummies Questions & Answers 2 12-03-2008 07:46 AM
append data in a file by using tab delimiter Sharmila_P Shell Programming and Scripting 6 07-31-2008 01:07 AM
get the data from sybase and append to the file vinay123 Shell Programming and Scripting 1 06-13-2008 09:25 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-02-2009
ravi_rn ravi_rn is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 19
Thumbs down How to Append the specific data to the xml file

I have an xml file data as shown below:

<impl name="Nortel" is-enabled="true">
<package-mappings>
<const-mapping target-state="EndPoint"
target-param="cfCNDSubscribed" constant-value="true"/>
<const-mapping target-state="EndPoint"
target-param="cfCWSubscribed" constant-value="true"/>
<const-mapping target-state="EndPoint"
target-param="cfCFVSubscribed" constant-value="true"/>
</package-mappings>

I want to append few line to the last that is after </package-mappings>

i am using the following script
but it seems to be not working

cat File.xml|sed '/\(.*<impl name=\"Nortel\" *is-enabled=\"true\".*\)/{
N
s:\(.*<impl name=\"Nortel\" *is-enabled=\"true\".*\)\n\( *\)<\/impl>.*$:\1\
\2<attribute max-instances="1" min-instances="0">\
\2 <simple-attribute name="securityLevel" type="number"\
\2is-key-field="false" is-package-defined="false">\
\2</attribute>:
}'

Please some one can help me out in the above issue.


Thank you very much in advance
  #2 (permalink)  
Old 04-02-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361

Code:
data='<impl> .... </impl>
<attribute max-instances="1" min-instances="0">
<simple-attribute name="securityLevel" 
  type="number" is-key-field="false" is-package-defined="false">
</simple-attribute>'

printf "%s\n" "$data" >> File.xml

Last edited by cfajohnson; 04-03-2009 at 03:40 AM..
  #3 (permalink)  
Old 04-03-2009
ravi_rn ravi_rn is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 19
Thumbs down

Actually my problem is, i have a data like below
<impl name="Nortel" is-enabled="true">
<package-mappings>
<const-mapping target-state="EndPoint"
target-param="cfCNDSubscribed" constant-value="true"/>
<const-mapping target-state="EndPoint"
target-param="cfCWSubscribed" constant-value="true"/>
<const-mapping target-state="EndPoint"
target-param="cfCFVSubscribed" constant-value="true"/>
<const-mapping target-state="EndPoint"
target-param="cfCFBLSubscribed" constant-value="true"/>
<const-mapping target-state="EndPoint"
target-param="cfCFDASubscribed" constant-value="true"/>
<const-mapping target-state="EndPoint"
</package-mappings>
<attribute max-instances="1" min-instances="0">
<simple-attribute name="lineNumber" type="string"
sub-type="number" is-key-field="false" is-package-defined="false">
<description>Telephone Number.</description>
<help>Subscriber's Telephone Number. </help>
</simple-attribute>
</attribute>

<attribute ....
</attribute>

</impl>

i want to the below data after </package-mappings> and above <attribute tag

below is the regular expression i am using to add but it is adding above
<package-mappings> but i have to add after </package-mappings>

The script i am using is
cat $i|sed '/\(.*<impl name=\"NueraWithNortel\" *is-enabled=\"true\".*\)/{
N
s:\(.*<impl name=\"NueraWithNortel\" *is-enabled=\"true\".*\)\n\( *\)<package-mappings>.*$:\1\
\2<attribute max-instances="1" min-instances="0">\
\2 <simple-attribute name="securityLevel" type="number"\
\2 is-key-field="false" is-package-defined="false">\
\2 <description>securityLevel</description>\
\2 <help>security level of the end pont</help>\
\2 </simple-attribute>\
\2</attribute>\
\2<package-mappings>:
}'
Please help me in resolving the issue
thank you very much in advance.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:21 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0