Replace the .txt file between two strings in XML file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace the .txt file between two strings in XML file
# 1  
Old 06-04-2013
Replace the .txt file between two strings in XML file

Hi i am having XML file with many number of lines,I need to replace between two strings with .txt file using awk.
For ex
Code:
<PersonInfoShipTo ------------------------------ />
My requirement is to replace the content between 
<PersonInfoShipTo ------------------------------ />

help me.
Thanks for ur help....

Last edited by Scott; 06-04-2013 at 06:40 AM.. Reason: Code tags
# 2  
Old 06-04-2013
try....
Code:
 
awk '/<PersonInfoShipTo ------------------------------ \/>/{p=1;print;print "Your text to be replaced"}/<PersonInfoShipTo ------------------------------ \/>/{p=0}!p' filename

# 3  
Old 06-04-2013
hi thanks for ur reply,
I am having many lines between <PersonInfoShipTo and /> i cant give all the line in program,one more thing i need to replace with a file with .txt extension
# 4  
Old 06-04-2013
use start with ^ and * if you have many charachter in the file and in unix dont worry about file extention just give your file name to the command.

ex:
Code:
 
awk '/^<PersonInfoShipTo*/{p=1;print;print "Your text to be replaced"}/^<PersonInfoShipTo*/{p=0}!p' filename.txt

# 5  
Old 06-04-2013
Hi i tried the below one,Because my end string is /> and replacement file is file6.txt
but i am getting below error.
awk: syntax error near line 1
awk: bailing out near line 1
Please help me

Code:
awk '/^<PersonInfoShipTo*/>$/{p=1;print;print "file6.txt"}/^<PersonInfoShipTo*/{p=0}!p' inputcopy.xml

# 6  
Old 06-04-2013
Quote:
Originally Posted by Padmanabhan
Hi i tried the below one,Because my end string is /> and replacement file is file6.txt
but i am getting below error.
awk: syntax error near line 1
awk: bailing out near line 1
Please help me

Code:
awk '/^<PersonInfoShipTo*/>$/{p=1;print;print "file6.txt"}/^<PersonInfoShipTo*/{p=0}!p' inputcopy.xml

Use nawk or /usr/xpg4/bin/awk on Solaris.
# 7  
Old 06-04-2013
hi i tries with nawk but i get the follwing error
Code:
nawk '/^<PersonInfoShipTo*/>$/{p=1;print;print "file6.txt"}/^<PersonInfoShipTo*/{p=0}!p' inputcopy.xml

Code:
nawk: syntax error at source line 1
 context is
         >>> /^<PersonInfoShipTo*/>$/ <<< {p=1;print;print "file6.txt"}/^<PersonInfoShipTo*/{p=0}!p
nawk: bailing out at source line 1

Please help me out

Last edited by radoulov; 06-04-2013 at 09:36 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Replace character string in txt file using input file(S)

Hi I have a large txt file on my AIX server and I need to replace some text using two other files. So filename1 has about 500 lines similar to: txtcode SYStem100 I have the string I want to change in string2 and the new stringname in string3. Does anyone know a way of doing this? I have... (1 Reply)
Discussion started by: Grueben
1 Replies

2. Windows & DOS: Issues & Discussions

2 Questions: replace text in txt file, add text to end of txt file

so... Lets assume I have a text file. The text file contains multiple "#" symbols. I want to replace all thos "#"s with a STRING using DOS/Batch I want to add a certain TEXT to the end of each line. How can I do this WITHOUT aid of sed, grep or anything linux related ? (1 Reply)
Discussion started by: pasc
1 Replies

3. Shell Programming and Scripting

Replace Contents between 2 strings in a file with contens of another file

Please I want to replace all the contents beween "Section" and "Ensection" in file1 with all contents in file2. Example: file1: Section "Screen" DefaultDepth 24 SubSection "Display" Depth 8 ViewPort 0 0 Modes "1024x768" "800x600" "640x480" EndSubsection SubSection "Display" Depth... (9 Replies)
Discussion started by: powelltallen
9 Replies

4. Shell Programming and Scripting

Extract strings within XML file between different delimiters

Good afternoon! I have an XML file from which I want to extract only certain elements contained within each line. The problem is that the format of each line is not exactly the same (though similiar). For example, oa_var will be in each line, however, there may be no value or other... (3 Replies)
Discussion started by: bab@faa
3 Replies

5. UNIX for Advanced & Expert Users

Find and replace txt between two strings in flat file

Hi There... I need to serach and replace strngs in a text file. My file has; books.amazon='Let me read' news.bestseller='xyz' expected output is books.amazon=NONFOUND news.bestseller=NONFOUND Can I first find the text between string1= books.amazon=' and string2= ' (locate the text... (1 Reply)
Discussion started by: Hiano
1 Replies

6. Shell Programming and Scripting

replace a string with contents of a txt file containing multiple lines of strings

Hello everyone, ive been trying to replace a string "kw01" in an xml file with the contents of a txt file having multiple lines. im a unix newbie and all the sed combinations i tried resulted to being garbled. Below is the contents of the txt file: RAISEDATTIME --------------------... (13 Replies)
Discussion started by: 4dirk1
13 Replies

7. Shell Programming and Scripting

Read file and for each line replace two variables, add strings and save output in another file

Hi All, I have a file, let's call it "info.tmp" that contains data like this .. ABC123456 PCX333445 BCD789833 I need to read "info.tmp" and for each line add strings in a way that the final output is put /logs/ua/dummy.trigger 'AAA00001.FTP.XXX.BLA03A01.xxxxxx(+1)' where XXX... (5 Replies)
Discussion started by: Andy_ARG
5 Replies

8. Shell Programming and Scripting

Parsing txt, xml files and preparing csv file

Hi, I need to parse text, xml files to get the statistic numbers and prepare summary csv file. What is the best way to parse these file and prepare csv file. Any idea you have , please? Regards, (2 Replies)
Discussion started by: LinuxLearner
2 Replies

9. Shell Programming and Scripting

How to convert a txt file to xml file

Hello, I donot have exact lenght of the file. But i want entire txt of the file to send it into one node. for example I have txt file.. asdfghjklmnbvcxzqwertyuiop., nswwneikniniwn so i need the output as <documentbody>asdfghjklmnbvcxzqwertyuiop., ... (9 Replies)
Discussion started by: Hemantgupta84
9 Replies

10. Shell Programming and Scripting

serach and replace file name in the path in a remote xml file

hi every one , here is my problem !! i have to run my script from an account and update the result in a xml file located on a different account. i use existing ssh keys to do it remotely for example the tags looks like this <PropertyValueList... (1 Reply)
Discussion started by: kiranreddy1215
1 Replies
Login or Register to Ask a Question