#!/usr/bin/ksh
while read f1 f2 f3 f4; do
case $f1 in
f2f*) echo "$f2 | $f4" >> fb_$f1;;
retire*) fname=$(echo $f1 | sed 's/_/_fb_/'); echo "$f2 | $f4" >> $fname;;
*) echo Boo! This is not supported!
esac
done < $1
Give the file that contains the records as argument to the script. Note that no error checking / input validation is carried out.