Mass Text Replace in Multilple Text Files?

Discussion in 'Software' started by KID52, 30 Jan 2008.

  1. KID52

    KID52 Minimodder

    Joined:
    19 Aug 2007
    Posts:
    335
    Likes Received:
    6
    I have ~100 text files and each have the same typing error in them, I am looking for a program that will allow me to open all of them and then replace a certain piece of text in all 100.

    For example, I want to open up all the text files, choose replace and replace "text1" with "text2" in every text file, but not have to do it manually.

    Any help on this would be great.

    Thanks
     
  2. DougEdey

    DougEdey I pwn all your storage

    Joined:
    5 Jul 2005
    Posts:
    13,933
    Likes Received:
    33
    if you're using linux (or have access to it), open up vi(m)

    esc then enter:

    :1,$s/text1/text2/g

    then

    :wq

    then for each subsequent file:

    :1,$s
    :wq

    The first two say replace text1 with text two on all lines, wq means write quit

    The second set will repeat the search/replace without typing everything in.
     
  3. KID52

    KID52 Minimodder

    Joined:
    19 Aug 2007
    Posts:
    335
    Likes Received:
    6
    Thanks for the reply, I did have linux installed as a virtual machine, but had to remove it as I ran out of disk space :( So ideally I need something that would work on Windows.
     
  4. Glider

    Glider /dev/null

    Joined:
    2 Aug 2005
    Posts:
    4,173
    Likes Received:
    21
    gvim works on windows... but it won't be fast doing it file by file... If you mail/PM me what needs to be changed, I'll sort it out with a bash script for you
     
  5. BlueTrin

    BlueTrin What's a Dremel?

    Joined:
    15 Dec 2007
    Posts:
    307
    Likes Received:
    1
    If you do not like Nix tools you can use Ultra Edit 32 if I remember well ...

    It has a tickbox to apply the changes to all files in a folder or something like that ...

    If you are familiar with Nix shells (bash, tcsh ... etc), you can use find. If you do not know how to use the find command on unixes, you can type "man find" the Linux man for find has an example on how to apply a command on every file.

    Then you can use sed to make text transformations.

    If you are familiar with Perl, it is quite easy and should not take more than few lines ...
     

Share This Page