Aqui está uma maneira com sed
:
sed -n 'H # append every line to hold buffer
/CREATE\|REPLACE/h # if CREATE or REPLACE, overwrite hold buffer
/;/{ # if line matches ; then
x # exchange hold space w. pattern space
/CREATE/w file1 # if pattern space matches CREATE, write to file1
/REPLACE/w file2 # if it matches REPLACE, write it to file2
}
' infile