February 23rd, 2013, 05:25 AM
Howto search and replace text files?
I have 2 text files like this:
Text file 1 contains:
Text file 2 contains:
I want to do a search and replace on text file 1 to get this:
WK = 0024.3 = werkschakelaar
NSIN = 0025.0 = netschakelaar in
GSIN = 0025.1 = gen.schakelaar in
BL = 0025.2 = blokkeerschakelaar
SYN1 = 0025.3 = omschak.met synchronisatie
SYN2 = 0026.0 = synchronisatie kommando
STNS = 0026.1 = storing netschakelaar
How should I do this? Is there a program available for this? If not anyone can think of a simple algoritme to get it done.
LN NSIN = 0025.0 = netschakelaar in
A GSIN = 0025.1 = gen.schakelaar in
LN GSIN = 0025.1 = gen.schakelaar in
February 23rd, 2013, 06:38 AM
Yes, you could do this in C or C++, but it might be faster to write the code out in perl or python or some such scripting language which has good string functions. What OS and compiler do you have?
The best way to do this is to read file 2 into a hash table first, using the numbers as the hash keys. Then read file 1, one line at a time and check the hash to see if you have a key match. If so, output the hash value, otherwise output the line alone.
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne
"I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
February 23rd, 2013, 07:13 AM
I have a win7 OS and a C and C++ compiler. I know a bit of C and C++, but haven't written a C/C++ program in a long time.
Thanks for the suggestion. I will look into it.