ok, so here is the issue, I have 2 arrays.
I need to be able to create a loop that will find ${ARRAY1[1] in the text doc, and replace it with ${ARRAY2[1] then write the results. I already have that working. The problem is, I need it to do that same result across however many items are in the 2 arrays (they will always be an equal # and will always match instances in the target text file)
So, here is what I have so far
This is doing what I need it to do. The problem tho, is that, obviously it is printing ${FILE}.txt over and over and in each instance it is replacing the corresponding array value.
I need do the find/replace across all arrays then output the final result to a new file that contains all of the new data.
I tried:
thinking, logically that would do the find and replace, open the new version containing the first find and replace do the next, etc until it resulted in what I need.
I end up with a blank document.
can somebody please tell me where I'm going wrong here.
I'm so close, I just don't know where to go from here!
Try this:
sed -i.bak 's/'${ARRAY1[$i]}'/'${ARRAY2[$i]}''/'g' ${FILE}.txt
That worked! You are a master!!
---------- Post updated at 10:21 PM ---------- Previous update was at 07:33 PM ----------
The next problem I'm getting now is it seems to be operating across not exact strings.
so what this is doing is replacing a series of lines names "Read#" with lines "[filename]"
the problem is, the targets are getting replaced in bulk and ruining the entire script. So rather than replace Read1 with [file in applicable array slot] it is replacing Read1. Read10, Read11 etc.
The only one I want to change in that instance is
the rest are just residual from it replacing all instances instead of the exact match.
I have tried
but that results in nothing changing for some reason. If anyone has a way to get this to work it would be a great help! Thanks!
---------- Post updated at 11:37 PM ---------- Previous update was at 10:21 PM ----------
is it possible to use a carriage return \n as a search string? like
or something like that?
---------- Post updated 08-14-12 at 09:35 AM ---------- Previous update was 08-13-12 at 11:37 PM ----------
Looks like that should work, I will try when I get in to work today.
##edit, that was it!
---------- Post updated at 12:30 PM ---------- Previous update was at 09:35 AM ----------