I searched for awhile and couldn\'t find a response to this. I have a standard tsv file with the following format:
1 100 101 350 A
1 101 102
So using grep, something like:
for L in `grep -oE '[A-Z]+$'|uniq|sort|uniq`
do
grep -E ${L}'$' > file.${L}.txt
done
The phrase grep -oE '[A-Z]+$'|uniq|sort|uniq
should find all the unique keys, which you then use to re-parse the file multiple times. The sequence uniq|sort|uniq is to reduce the input to sort.
If you really need to do it in a single pass, then you could process each line, and append it immediately to the appropriate output file.