Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

replace data in a file from data in another text file

Status
Not open for further replies.

sarah9680

Programmer
Jan 15, 2014
4
0
0
Hi everyone!

I am trying to create a batch of files from a master xml file. Everything will be the same except for 2 fields that I need to dynamically change for each created file. The data can be put in a data file to read from or any other suggestions on how to get these values to be read by the awk program?

I have the code to create the xml files and now i'm looking how to find and replace the 2 data values with specific values.

Example:

original xml file:

<Invoice>
<InvoiceNum>ABC</InvoiceNum>

<InvoiceLine>
<InvoiceLineNumber>0001</InvoiceLineNumber>

I would need to replace these values with values from a text value..

data file:

ABC, 123
DEF, 456

Thanks!
 
What have you tried so far and where in your code are you stuck ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 

You are not the only one working on this problem, it seems the whole class is wants the solution.
You should at least try to solve this on your own and perhaps someone will help you if you get stuck!
[reading]


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
I am trying to read the file into an array. And then when i loop through the file creation, i can pull the array data as my substitute.

I'm new to this and if anyone has a simple example i can use to read a file into an array that would get me started.

 
read a file into an array
Already a ton of examples posted here.
You may search this forum for nr==fnr or fnr==nr

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
ok, thanks! I will do a search on that!
 
Sarah said:
I am trying to read the file into an array. . .
Hi Sarah,

Sometimes the xml file does not have embedded line feed's (new line) that would separate the text in lines, but rather the whole xml is in one huge line.

Therefore, unless the xml file is formatted with line-feed's, reading the file into an array will not help at all.

Check out this post, perhaps it will help.
[flowerface]



----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
the file to be read in will just be a standard data text. It can be delimited by spaces, comma's etc.

The file that needs to be created/updated by the data will be the xml files.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top