• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Incremental replace functionality

cirrrocco

Golden Member
repost from Here.

Hey there, thanks for the response. I did not want to change an unique identifier in a bunch of files, but rather change the unique identifier in ONE file with the contents of a second file. so if i have ten instances of a unique identier say "****HHH***" in the first file, then lets suppose i have 10 different words each on a separate line. the first word from file 2 should replace the first instance of ****HHH*** in file 1 and the word on the second line should replace the second instance of ****HHH*** in file 1 and so forth.

ex:
COntents of file 1

ABCD = ABCD + ****HHH***
href=fox****HHH***.html
why does ****HHH*** fly high??

contents of second file

EFG
sucks
the bird

========
so after operation the content of file 1 should be

ABCD = ABCD + EFG
href=foxsucks.html
why does the bird fly high??


I hope that made sense.

======

so can someone find me a software that can do that, preferably one that a dumb user like me can run from my pc.

 
Given file1.txt, file2.txt, the unique identifier above, and Strawberry Perl, the following at the command line should do it:

perl -e "$uniqueid='\*\*\*\*HHH\*\*\*';open(IN, 'file2.txt');while(<>){while(/$uniqueid/){$rep=<IN>;$rep=~s/[\r\n]//g;s/$uniqueid/$rep/;}print;}close IN;" file1.txt > result.txt

It even works with multiple instances of the unique identifier on the same line.

Edit: Fixed, Thx Mark
 
Originally posted by: Ken g6
Given file1.txt, file2.txt, the unique identifier above, and Strawberry Perl, the following at the command line should do it:

perl -e "$uniqueid='\*\*\*\*HHH\*\*\*';open(IN, 'file2.txt');while(<>) {while(/$uniqueid/){$rep=<IN>;$rep=~s/[\r\n]//g;s/$uniqueid/$rep/;}print;}close IN;" file1.txt > result.txt

It even works with multiple instances of the unique identifier on the same line.

Edit: Weird forum problem; replace that wink with a single end-parenthesis.

When you post something that contains combinations that might be interpreted as emoticons, check the "Do not parse emoticons" checkbox at the bottom of the edit dialog. That will keep your text from being converted.
 
and also i am on a mac now, but will check it on xp once I get home. one question I had though was that is result.txt the output or will i have to check file1.txt after the replace is done. sorry I dont know any programming other than a lil bit html. Thanks Ken, Mark.
 
Back
Top