Searching for multiple instances of a phrase in a large text file

Discussion in 'Mac Apps and Mac App Store' started by ozaz, Nov 26, 2011.

  1. ozaz, Nov 26, 2011
    Last edited: Nov 26, 2011

    ozaz macrumors 65816

    Joined:
    Feb 27, 2011
    Location:
    UK
    #1
    I have a large text file (thousands of lines). I want to find all the lines that contain a particular phrase (of which there are many) and copy them to another file. Any text editor will search for the phrase but all the ones I use go to each instance of the phrase one-by-one. I'd like the result of the search to be the display of all the lines that contain the phrase (i.e hiding the lines that don't contain the phrase).

    Can anyone advise me on an app that will do this?

    Thanks
     
  2. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #2
    Wirelessly posted (Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3)

    Grep is built in and available from Terminal.app and will do exactly what you want.

    B
     
  3. waynep macrumors 6502

    Joined:
    Dec 31, 2009
    #3
    Open the terminal and use this command:

    grep "phrase" FILENAME > OUTPUT-FILENAME

    wayne
     
  4. ozaz thread starter macrumors 65816

    Joined:
    Feb 27, 2011
    Location:
    UK
    #4
    Thanks for telling me about grep.

    I have just found a way to do this without terminal. TextWrangler has a feature called "process lines containing.." (in the Text menu).
     

Share This Page