UNIX geeks : sed

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

  1. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    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 (uid = 0)

    Joined:
    Nov 14, 2000
    Messages:
    23,439
    Likes Received:
    11
    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