#/bin/ksh
let filecnt=0
while read record
do
if [ `echo $record | grep -q '^ABC'` -ne 0 ] ; then
echo "$record" > newfile"$filecnt"
let filecnt=$filecnt + 1
fi
done < oldfile
Out of interest, is possible to redirect the same output with sed to textfile.$count? using branching (b), hold space or whatsoever is available in sed to output different sections from one file to more than files?
$ < infile awk '/ABC/{c++; next} {print > "outfile." c}'
$ head outfile.*
==> outfile.1 <==
/ Some text /
==> outfile.2 <==
/ Some text /
==> outfile.3 <==
/ Some text /
==> outfile.4 <==
/ Some text /
==> outfile.5 <==
/ Some text /