Help sorting a very large txt file!?

Discussion in 'macOS' started by MacBook MH, Jan 15, 2011.

  1. MacBook MH macrumors member

    Joined:
    Mar 7, 2009
    #1
    Hi everyone.
    I got a text file with more than 10 000 entries. Down below there is a preview of its contents:



    there are only 4 possibilities what can be in the [] brackts. What I want to do is to copy the word before the [] brackets to a specific file depending to the contents of the []. So if there is [ý] or [y] after the word (or group of words in the specific line) copy it to document "y.txt". If there is [í] or after the word (or group of words in the specific line) copy it to document "i.txt".

    The result should look like:
    document i.txt
    document y.txt
    is there any program to do this??? or a terminal command??? PLEASE HELP ME!!! IT IS EXTREMELY IMPORTANT!

    THANKS IN ADVANCE!
     
  2. ssmed macrumors 6502

    ssmed

    Joined:
    Sep 28, 2009
    Location:
    UK
    #2
    A possible way of doing this

    I would import into an Excel Spread sheet or database (Filemaker or 4D for instance) and then filter for the correct entries and export. Doing it this way should take a matter of minutes.
     
  3. LPZ macrumors 65816

    Joined:
    Jul 11, 2006
    #3


    You could try the following:

    1) Make a copy of your file, name it input.txt, and place it in your Home folder.

    2) Open Terminal (in Utilities), copy and paste the following line into the Terminal window, and press return:

    Code:
    cd; cat input.txt | grep -F -e [y -e [ý | cut -d [ -f 1 > y.txt
    You should get a file named y.txt containing what you want.

    If so, enter the following to get a file named i.txt

    Code:
    cat input.txt | grep -F -e [i -e [í | cut -d [ -f 1 > i.txt
     

Share This Page