How to replace some chars in a txt file and compare two ?

Discussion in 'Mac Apps and Mac App Store' started by CmdrLaForge, May 24, 2004.

  1. CmdrLaForge macrumors 68040

    CmdrLaForge

    Joined:
    Feb 26, 2003
    Location:
    around the world
    #1
    Hello,

    I need a little help. Maybe someone how knows about unix or Apple script.

    I need to compare two huge textfiles. But before comparing I need to replace in one of the files character xyc with yxc or similar.

    Problem is that the files are huge. I mean HUGE. Word cannot open them and Excel neither. Much too big for both apps.

    Would be great if someone had an idea. Windows would work as well.

    Thanks and regards
    CmdrLaForge :confused:
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Unix to the rescue! The comparason is easy. Use diff. I.e. in the terminal type

    diff file1 file2 > file_diffs.txt

    You will now have a new file called file_diffs.txt with the differences listed.


    Bur before that we need to do the text replacement. So lets use sed. Sed is the Unix Stream Editor. To replace all instances of xyc with yxc in a file called file1 do:

    sed "s/xyc/yxc/" file1 > new_file1

    You now have a new file called new_file1 with the instances of xyc replaced with yxc. Your original file has not been harmed.

    For more info on either command type man <command>
     
  3. CmdrLaForge thread starter macrumors 68040

    CmdrLaForge

    Joined:
    Feb 26, 2003
    Location:
    around the world
    #3
    Great !!! Thanks a lot !


    Do you know if there is a way to use these unix commands under a Windows environment. I have heard that there are free shells.

    Cheers
    CmdrLaForge
     
  4. tomf87 macrumors 65816

    tomf87

    Joined:
    Sep 10, 2003
  5. CmdrLaForge thread starter macrumors 68040

    CmdrLaForge

    Joined:
    Feb 26, 2003
    Location:
    around the world
    #5
    Thanks ! I will try that.

    Cheers
     

Share This Page