Jm2005
asked on
Replace Strings with Strings from a file.
i'm looking to create a for loop or something similar to accomplish the following.
ive got files, one with a list of the text i want to replace.
i'll refer to this as the source file:
example:
<description>test.0</descr iption>
<description>test.1</descr iption>
<description>test.2</descr iption>
etc..
the destination has similar entries, but i need to replace each line with one from the source sequentially... would a for loop do this properly?
ive got files, one with a list of the text i want to replace.
i'll refer to this as the source file:
example:
<description>test.0</descr
<description>test.1</descr
<description>test.2</descr
etc..
the destination has similar entries, but i need to replace each line with one from the source sequentially... would a for loop do this properly?
ASKER
file 2 has:
<description>somethingelse </descript ion>
<description>somethingnott hesame</de scription>
i want file1's data to replace file 2's <description> tag
<description>somethingelse
<description>somethingnott
i want file1's data to replace file 2's <description> tag
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
okay, i was mistaken:
i need to change between the descriptions in file 2
file one is the values i need to change them to, in sequential order. there is no reference between them otherwise.
i need to change between the descriptions in file 2
file one is the values i need to change them to, in sequential order. there is no reference between them otherwise.
Sorry if I'm overlooking the obvious, but if you take the values between the description tags in file 1 and replace the values between the description tags in file 2, don't you just have a copy of file 1, since the format of both files is the same?
Do the files have different numbers of records, which would make the resulting file different than either of the sources? If so, how do you want to resolve the differences?
Do the files have different numbers of records, which would make the resulting file different than either of the sources? If so, how do you want to resolve the differences?
ASKER
i was wrong about file 2..
file 2 is just a list of values to put into file1's description tags, and they are different.
they are the same exact number of records.
file 2 is just a list of values to put into file1's description tags, and they are different.
they are the same exact number of records.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
that while read x; do echo "<description>"$x"</descri ption>"; done <file2.txt works, but i need to replace the description tags in the files.
ASKER
the second file has other data i dont want to damage.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ive tried this:
for i in $(cat change); do cat tempate.xml |sed 's/<description>ifAdminSta tus.*/<des cription>c onnection to '$i'<\/description>/'; done | less
but it replaces EVERY entry with the first line in change and it loops infinitely until i kill it.
for i in $(cat change); do cat tempate.xml |sed 's/<description>ifAdminSta
but it replaces EVERY entry with the first line in change and it loops infinitely until i kill it.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I'll re-iterate arnold's request. Please post a sample of both files. As arnold said, once we know exactly what you're trying to do, it's simple to craft a short perl program to do it.
You have file1 that has:
<description>test.0</descr
<description>test.1</descr
<description>test.2</descr
You have file2 that has:
test.0 somenewname
test.1 anothername
test.2 completelynewname
After the script run you want for file1 to have:
<description>somenewname</
<description>anothername</
<description>completelynew
Is that right?
perl might be better if the above is representative of the data.
i.e. build a hash from the second file based on the name-> replacementname