grep -E '^foo' input.txt > foo.txt
grep -E '^bar' input.txt > bar.txt
mbp-000234: ~ dmourati $ cat foo.txt
foo xxx yyy zzz
foo xxx yyy zzz
foo xxx yyy zzz
foo xxx yyy zzz
foo xxx yyy zzz
mbp-000234: ~ dmourati $ cat bar.txt
bar xxx yyy zzz
bar xxx yyy zzz