atw: Re: Multiple text string find and replace in multiple documents

  • From: "Petra Liverani" <petral@xxxxxxxxxxxx>
  • To: austechwriter@xxxxxxxxxxxxx
  • Date: Fri, 17 Aug 2018 08:01:37 +0800

Thanks Rhonda, Peter and Stuart for your replies. I will look at the
suggestions over time though from a casual skimming none of them are
obviously for multiple strings. It seems multiple file search tools
are quite common but not multiple string searches unless you use
programming code - which I have no expertise with.
I'm working with html files and I'm not quite sure whether it's worth
using a tool or simply doing the changes manually because the changes
are not necessarily straightforward. The possible number of strings
would be about 350 as are the number of files. But there are other
possible string changes too. I just thought it would be good to have a
tool on hand. But then there's the SOE environment to get around.
Apparently, they're not keen on giving admin rights so there are a
number of considerations to keep in mind.
My sister came up with this Powershell script below that she found on
the internet and it seems to work - if anyone else ever needs to do
the multiple string/multiple file find and replace.
Regards,Petra

I have managed to get a powershell script off the net which does it,
but running powershell scripts when you don't have admin rights can
have problems. I can run it on my powershell but first I have to run
the command:
set-executionpolicy unrestricted
and I can only run that command when I run powershell as
administrator.
So you probably won't be allowed to run a powershell command as a
non-admin user. It depends on how your PCs are set up.
You can also download "sed" for windows. Sed is the tool I would
probably use in linux to do it. It is ideal for search, replace.
This is the powershell script. You would save this text as a ps1 file.
I am also attaching the ps1 file but sometimes mail doesn't allow them
through so I have it below as text
I am attaching the Input.csv file which is what you gave me but I have
created as a csv file with headings. The headings are needed for the
script to work.You would have to modify the script to give the
location of the csv file which has the find/replace strings and to
change location of where the text files are.
******  IMPORTANT: THis script modifies the files in place. It does
not create new files so  you would be best to do a backup first.
Someone complained on the net that this script also puts in an extra
line feed at the end of the file.

#----------------------------------------------------# Title:
replaceStrings
$fdPath = 'c:datatest'$textFiles = Get-ChildItem -Path $FDPATH*.txt |
ForEach-Object FullName$findReplaceList = Import-Csv -Path
$FDPATHInput.csv

$totalitems = $textFiles.count$currentrow = 0foreach ($textFile in
$textFiles){    $currentrow += 1    Write-Progress -Activity
"Processing record $currentrow of $totalitems" -Status "Progress:"
-PercentComplete (($currentrow / $totalitems) * 100)    [string]
$txttextFile = Get-Content $textFile | Out-String        ForEach
($findReplaceItem in $findReplaceList)    {        $txttextFile
= $txttextFile -replace "$($findReplaceitem.FindString)",
"$($findReplaceitem.ReplaceString)"    }        $txttextFile |
Set-Content
($textFile)}#---------------------------------------------------------------------------------

----- Original Message -----
From: austechwriter@xxxxxxxxxxxxx
To:
Cc:
Sent:Thu, 16 Aug 2018 14:32:12 +0800
Subject:atw: Re: Multiple text string find and replace in multiple
documents

Petra, are you working with text files or Word documents? 

The tool you liked, Replace Text, looks like it's for text files and
explicitly not for Word docs. EditTools looks like it's for Word docs,
not for text files.

I was going to recommend WildEdit. Distant memory tells me it handles
multiple find strings, but  suggests not.

Can you say any more about the sort of changes you need to do? Is this
a one-off conversion/tidy-up, or is it something you expect to do
repeatedly? About how many find strings and source files are there?
(E.g. 10 or 100 find strings? Hundreds of source files or thousands?)
Are you changing text (words and punctuation) or tagging (HTML or
XML)?

--- Stuart

----- Original Message -----

EditTools does this – I haven’t used it, but I know it can do it.
http://www.wordsnsync.com/edittools.php [1], specifically
http://www.wordsnsync.com/multifile-find.php [2] ;

        Rhonda 

         

        FROM: austechwriter-bounce@xxxxxxxxxxxxx
[mailto:austechwriter-bounce@xxxxxxxxxxxxx] ON BEHALF OF Petra
Liverani
SENT: Thursday, 16 August 2018 12:44 PM
TO: austechwriter@xxxxxxxxxxxxx
SUBJECT: atw: Multiple text string find and replace in multiple
documents

         

        Hi all,

        Does anyone know of a tool where you can do multiple text string find
and replace in multiple documents, with priority on the multiple text
string rather than the multiple documents.

        I found a seemingly fantastic tool, Replace Text
(http://www.ecobyte.com/replacetext/), which would seem to perform
both functions easily but it is no longer supported and I notice it
mentions that there is a problem with Windows 7 so I'm assuming the
fact that I can't make it work in Windows 10 is to do with lack of
upgrade. Such a shame because it seems so powerful and I cannot
understand why there does not seem to be an equivalent either free or
paid.

        My sister is looking at what she can do in Powershell but I wondered
if anyone knew of a tool for non-programming types. I realise you
could do a macro in Word but I want to do it for quite a large number
of strings and I imagine Word wouldn't really like that very much. I
think a specific tool would work much better. There's textcrawler but
as far as I can tell that searches single strings in multiple files.

        Regards,
Petra
   

Links:
------
[1] http://www.wordsnsync.com/edittools.php
[2] http://www.wordsnsync.com/multifile-find.php

Other related posts: