The file to read is file.sql containing following text create table temp (name varchar(20), id number)  on commit reserve rows;create table temp1  (name varchar(20), id number) on commit reserve rows;select name, id from temp where id=21;I want the three queries stored in three different files as below file1.sqlcreate table temp  (name varchar(20), id number)  on commit reserve rows file2.sqlcreate table temp1 (name varchar(20), id number)  on commit reserve rowsfile3.sqlselect name, id from temp where id=21using ksh scripting  while retaining whitespaces
Read a text file and its store contents into different files or variables
files;ksh;read
re='create table'csplit -s -k -f file. yourSqlFile %^$re% /^$re/ '/^select name,/' '/./'for f in file.[0][0-3]; do   k=${f#*.0}   mv $f file$k.sqldonefor i in {2,1,0};do   j=$((i + 1))   mv file$i.sql file$j.sqldone