awk '/^t/{print > (/^tt/ ? "file2" : "file1")}' file
or maybe slightly faster since the above always does 2 regexp comparisons per line while the following only does 1 comparison for lines that start with tt:
awk '/^tt/{print > "file2"; next} /^t/{print > "file1"}' file
Here are the third-run timings for executing the above 2 scripts and all of the other solutions posted so far on a 10 million line file produced by duplicating the OPs input 2 million times using this script:
awk '{for (i=1;i<=2000000;i++) print}' file5 > file10m
ordered by speed of execution (slowest to fastest):
Anubahva's awk:
$ time awk 'match($0,/^t+/) {print > ("anubhava_outfile" RLENGTH)}' file10m
real 0m8.184s
user 0m8.042s
sys 0m0.124s
sexcpect's awk:
$ time awk '/^tt/ { print > "sexpect_file1" } /^t[^t]/ { print > "sexpect_file2" }' file10m
real 0m6.625s
user 0m6.480s
sys 0m0.128s
mathguy's 2 greps:
$ time { grep '^tt' file10m > grep_outfile1; grep -E '^t([^t]|$)' file10m > grep_outfile2; }
real 0m5.938s
user 0m5.812s
sys 0m0.111s
Eds awk 1:
$ time awk '/^t/{print > (/^tt/ ? "awk1_file2" : "awk1_file1")}' file10m
real 0m2.656s
user 0m2.535s
sys 0m0.110s
Eds awk 2:
$ time awk '/^tt/{print > "awk2_file2"; next} /^t/{print > "awk2_file1"}' file10m
real 0m2.604s
user 0m2.490s
sys 0m0.106s
Wiktor's awk:
$ time awk '{if($0 ~ /^tt/) {print > "wiktor_outfile1"} else if ($0 ~ /^t/) {print > "wiktor_outfile2"}}' file10m
real 0m2.421s
user 0m2.315s
sys 0m0.096s
So, no surprises there.
The above were run on a MacBook Pro with 2.2Ghz 6-Core Intel Core i7 processor with these versions of the tools:
$ grep --version
grep (BSD grep) 2.5.1-FreeBSD
$ awk --version
GNU Awk 5.0.1, API: 2.0 (GNU MPFR 4.0.2, GNU MP 6.1.2)
BSD awk was slower than GNU awk but BSD grep was faster than GNU grep so I used the timings from that fastest tools versions I have on my machine since that's what you'd use if you cared about performance.