You are here: PSPad forum > English discussion forum > Re: Multiple replaces
Posted by: Esgrimidor | Date: 2015-04-30 21:16 | IP: IP Logged
I have over 70 files to be modified.
I think i can do this in two ways.
Replacing the string in every one with the new one.
I have a txt file with the 70 email addresses i want to replace. I need to recognize the email in the old files.
Use a sort of csv file to replace in the files.
How can I do this ?
Best Regards
--
Nice program indeed
Posted by: Esgrimidor | Date: 2015-05-01 01:27 | IP: IP Logged
Script for replace substrings in a text file according to a csv file registries.
Best Regards
--
Nice program indeed
Posted by: Andreas | Date: 2015-05-03 23:48 | IP: IP Logged
I think you should do this with your prefered programming language. I for one would use PHP.
First read your CSV into an array. Build a $search Array and a $replace Array. Then in a loop read each file into a string and do a replace($search, $replace, $string). Finally write new string back to file.
Posted by: Esgrimidor | Date: 2015-05-04 13:15 | IP: IP Logged
Andreas:I think you should do this with your prefered programming language. I for one would use PHP.First read your CSV into an array. Build a $search Array and a $replace Array. Then in a loop read each file into a string and do a replace($search, $replace, $string). Finally write new string back to file.
I don't manage php. Sorry.
Perhaps an autohotkey or a batch file ?
Thanks a lot
Best Regards
--
Nice program indeed
Posted by: carbonize | Date: 2015-05-04 13:55 | IP: IP Logged
What exactly is it you want to do?
--
Carbonize
Posted by: Andreas | Date: 2015-05-04 16:32 | IP: IP Logged
Esgrimidor:Perhaps an autohotkey or a batch file?
Sorry, but those are not my languages.
Just to show you how simple it could be:
<?php
/**
* run.php
*/
/**
Folder structure:
ROOT/run.php
ROOT/data.csv
ROOT/files/file_01.txt
ROOT/files/file_02.txt
ROOT/files/file_03.txt
ROOT/new-files/
*/
// show some errors
error_reporting(E_ALL);
ini_set('display_errors', 1);
// set your variables here
$folder = 'files';
$newFolder = 'new-files';
$suffix = 'txt';
$csv = 'data.csv';
$csvDelim = ';';
// do nothing below this line
$files = glob($folder.'/*.'.$suffix);
$csvRows = file($csv);
// build the search and replace arrays
foreach($csvRows as $row)
{
list($search[], $replace[]) = explode($csvDelim, $row);
}
// the action
foreach($files as $file)
{
$fileContent = file_get_contents($file);
$fileContent = str_replace($search, $replace, $fileContent);
file_put_contents($newFolder.'/'.basename($file), $fileContent);
}
?>
Posted by: Esgrimidor | Date: 2015-05-19 00:20 | IP: IP Logged
I will keep the script until i can use it.
Thanks a lot.
Whta I try is update a lot of iMacros scripts.
--
Nice program indeed
Posted by: Andreas | Date: 2015-05-19 02:08 | IP: IP Logged
You only need a server with PHP running on it and typehttp://mydomain.org/run.php
into the address bar of your browser after you copied all files and folders to this server.
Posted by: Esgrimidor | Date: 2015-05-19 19:55 | IP: IP Logged
Thanks Andreas.
I don't have a dominion or web site .
I have blogs like these :
www.ingenierostenerife.tk
peritostenerife.wordpress.com
have i a server ?
--
Nice program indeed
Posted by: Andreas | Date: 2015-05-20 12:03 | IP: IP Logged
Esgrimidor:I don't have a dominion or web site.I have blogs like these:
www.ingenierostenerife.tk
peritostenerife.wordpress.com
have i a server?
Yes you should have access to the server that holds the domain ingenierostenerife.tk.
But oops, the domain www.ingenierostenerife.tk serves us a page with a frameset frame with content of http:// ingenierostenerife.blogspo*.com. And in this frame there's another iframe with the final content of http:// ingenierostenerife.blogspo*.com. That's not the right and not the nice way.
<html>
<head>
<title>Ingenieros Tenerife</title>
</head>
<frameset>
<frame src="http://ingenierostenerife.blogspo*.com">
<html>
<head></head>
<body>
<iframe src="http://ingenierostenerife.blogspo*.com/"></iframe>
</body>
</html>
</frame>
</frameset>
</html>
You should have access to the server which hosts ingenierostenerife.tk and then in the server settings you should do a redirect (forwarding) to http:// ingenierostenerife.blogspo*.com.
Users should see the domain where content is hosted. With this frames you're pretending a wrong domain.
If you have no provider that offers you a server with PHP you can install a local server on your PC like xampp, wamp, lamp, zwamp or mamp which offers you a PHP, MySQL, Apache combo environment. After installing you only have to run it if you need it. But doing it on a live server is the easiest way.
If you have access to server with ingenierostenerife.tk you can create a subdomain playground.ingenierostenerife.tk create a folder on that server /playground/ and redirect the subdomain to this folder to do your PHP experiences in there.
Editor PSPad - freeware editor, © 2001 - 2024 Jan Fiala, Hosted by Webhosting TOJEONO.CZ, design by WebDesign PAY & SOFT, code Petr Dvořák, Privacy policy and GDPR