csplit -f out inputfile '/SEL/' grep 'CBLO' out00 >tmp1 sed 's/.*/&,BUY/' tmp1 >finalout grep 'CBLO' out01 >tmp2 sed 's/.*/&,SEL/' tmp2 >>finalout