for a in `tee q` { for i in {0..99} { [ `grep -c ^${a:0:i} q` = 1 ]&&echo ${a:0:i}&&break } }