Windows Vista Forums

Search and replace in a text file?
  1. #1


    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

  2. #2


    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

  3. #3


    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

  4. #4


    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

  5. #5


    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

  6. #6


    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

  7. #7


    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

  8. #8


    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

  9. #9


    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

Search and replace in a text file? problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Search and replace text inside an htm file Rafael PowerShell 1 13 Mar 2010
Search and Replace text file very slow jerschmidt14 PowerShell 4 02 Jun 2009
search and replace in binary file Tony Logan VB Script 4 10 Nov 2008
How to search and replace text in a string Jason Murray PowerShell 8 07 Jan 2008
Search for Text in UTF-8 File Webbert Vista General 1 16 Jul 2007