UNIX geeks : sed

Discussion in 'OT Technology' started by SLED, Aug 29, 2005.

  1. SLED

    SLED custom title

    Joined:
    Sep 20, 2001
    Messages:
    28,122
    Likes Received:
    12
    I have 1 big file that has a bunch of tab delimited data by state. Say the first column is state. I want to go through the file with sed per state, and have it break out all the data into 1 file for each state. Anybody know how to do this?
     
  2. crontab

    crontab Oracle doesn't have customers, they have hostages.

    Joined:
    Nov 14, 2000
    Messages:
    24,197
    Likes Received:
    217
    I can't do it in sed.

    for i in `cat file.txt | awk '{print $1}' | sort | uniq`
    do
    grep $i file.txt > $i.file.txt
    done

    This assumes that the state is only used once per line.
     

Share This Page