My friend Pierre found another way to solve the same problem using the Nedit text editor:
The following Nedit macro does the same thing you described.
I haven't tested it on a large file though (the macro below reads the entire file in memory...) This simple example takes a file1 with values to search for and replaces the contents of file2. Nedit has a nice C-like macro language (documented here:www.nedit.org/ftp/contrib/misc/nedit.pdf)
file1
value_to_search1 value_to_replace1
value_to_search1 value_to_replace1
etc
A macro can be added to Nedit by selecting:
Preferences->Default Menu->Customize Menu->Macro Menu
A dialog window pops up, select New, name your macro add it in the macro editor and click on Apply. After it will appear in the Macro menu and can be executed from there.
========== nedit edit macro ====================
t_print("Automatic Search & Replace","\n")
file1 = read_file("/home/pierre/tmp/nedit/file1")
file2= read_file("/home/pierre/tmp/nedit/file2")
file1_array = split(file1,"\n")
for(i=0;i<file1_array[]-1;i++) {
line_array = split(file1_array
i," ")
file2= replace_in_string(file2,line_array[0],line_array
1)
}
write_file(file2,"/home/pierre/tmp/nedit/file2_changed")
=================================================
I should note that Pierre's "Nedit" technique doesn't solve the
foo bar
ba BAH
problem, but this may be a good enough solution for many cases.
- Chris Koknat