Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Search and replace in a text file?

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 05-25-2007   #1 (permalink)
Stuart Grimshaw
Guest


 

Search and replace in a text file?

Is there an easy way to search for a string in a text file, and
replace it with something else? Preferably using a regex, but it's not
really that important.


My System SpecsSystem Spec
Old 05-25-2007   #2 (permalink)
RichS
Guest


 

RE: Search and replace in a text file?

There is a script here
http://safari.oreilly.com/9780596528...text_in_a_file

that looks like it will do what you want
--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"Stuart Grimshaw" wrote:

> Is there an easy way to search for a string in a text file, and
> replace it with something else? Preferably using a regex, but it's not
> really that important.
>
>

My System SpecsSystem Spec
Old 05-25-2007   #3 (permalink)
Marco Shaw
Guest


 

Re: Search and replace in a text file?

RichS wrote:
> There is a script here
> http://safari.oreilly.com/9780596528...text_in_a_file
>
> that looks like it will do what you want


That's on safari... Gonna need to pay to see the solution.

Marco
My System SpecsSystem Spec
Old 05-25-2007   #4 (permalink)
Marco Shaw
Guest


 

Re: Search and replace in a text file?

Stuart Grimshaw wrote:
> Is there an easy way to search for a string in a text file, and
> replace it with something else? Preferably using a regex, but it's not
> really that important.
>


Googled and found this:
http://weblogs.asp.net/efrancobisi/a...ple-files.aspx
My System SpecsSystem Spec
Old 05-25-2007   #5 (permalink)
RichS
Guest


 

Re: Search and replace in a text file?

The actual script is on a preview free to view section. You need to pay if
want to see whole chapter
--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"Marco Shaw" wrote:

> RichS wrote:
> > There is a script here
> > http://safari.oreilly.com/9780596528...text_in_a_file
> >
> > that looks like it will do what you want

>
> That's on safari... Gonna need to pay to see the solution.
>
> Marco
>

My System SpecsSystem Spec
Old 05-25-2007   #6 (permalink)
hecks@hotmail.co.uk
Guest


 

Re: Search and replace in a text file?

On May 25, 8:27 am, Stuart Grimshaw <stuart.grims...@gmail.com>
wrote:
> Is there an easy way to search for a string in a text file, and
> replace it with something else? Preferably using a regex, but it's not
> really that important.


The no frills option:

(gc file.txt) -replace "oldstring","newstring" | sc file.txt

-Hecks

My System SpecsSystem Spec
Old 05-29-2007   #7 (permalink)
Stuart Grimshaw
Guest


 

Re: Search and replace in a text file?

On May 25, 6:03 pm, h...@hotmail.co.uk wrote:
> The no frills option:
>
> (gc file.txt) -replace "oldstring","newstring" | sc file.txt
>
> -Hecks


Cheers Hecks, the Tesco Value solution works for me.

-S

My System SpecsSystem Spec
Old 05-29-2007   #8 (permalink)
news.microsoft.com
Guest


 

Re: Search and replace in a text file?

PS C:\> type b.txt
this is a prod
text file for prod.

PS C:\> ${c:\b.txt} = ${c:\b.txt} -replace "prod","test"

PS C:\> ${c:\b.txt}
this is a test
test file for test.

PS C:\>

"Stuart Grimshaw" <stuart.grimshaw@gmail.com> wrote in message
news:1180448772.317454.106720@u30g2000hsc.googlegroups.com...
> On May 25, 6:03 pm, h...@hotmail.co.uk wrote:
>> The no frills option:
>>
>> (gc file.txt) -replace "oldstring","newstring" | sc file.txt
>>
>> -Hecks

>
> Cheers Hecks, the Tesco Value solution works for me.
>
> -S
>



My System SpecsSystem Spec
Old 06-01-2007   #9 (permalink)
Stuart Grimshaw
Guest


 

Re: Search and replace in a text file?

On May 30, 2:52 am, "news.microsoft.com" <xsh...@gmail.com> wrote:
> PS C:\> type b.txt
> this is a prod
> text file for prod.
>
> PS C:\> ${c:\b.txt} = ${c:\b.txt} -replace "prod","test"
>
> PS C:\> ${c:\b.txt}
> this is a test
> test file for test.
>
> PS C:\>
>


Cool, that's another way of doing it ...

My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Search & Replace on a word doc Hal Rottenberg PowerShell 4 07-27-2008 11:00 PM
search and replace string Ron PowerShell 1 06-16-2008 09:29 AM
How to search and replace text in a string Jason Murray PowerShell 8 01-07-2008 04:29 AM
regex - search - replace question Bin PowerShell 5 10-12-2007 12:13 AM
Search for Text in UTF-8 File Webbert Vista General 1 07-16-2007 10:52 AM


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51