Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I create a file with the contents of SQL Scripts?

Status
Not open for further replies.

chigs

Programmer
Jul 4, 2003
4
US
Hello

I have just stared work and this stupid little program is baffling me. I am only an intern so please don't scream.

I am using the Korn Shell

I have a directory of SQL files. eg boo.sql. I want to create one file with the content of all the sql files in the directory. But i also need to have the name of the file before the actual sql code in the new file. The files have no naming convention.

I know i have to write a korn script but i have no clue how to do this or what i need to include in the script (apart from the cat command. I have got somewhere)

Can anyone help?

Thanks

Chirag
 
You can try this:

#!/usr/bin/ksh -p

# Script to give file name and contents of sql in file.

echo "Master SQL File list with content...." >> master.lst

# Script must be in directory for this to work, if you want
# it outside the directory, you will have to include the
# directory path.

for x in `/usr/bin/ls *.sql`
do
echo "\n\n${x}:\n\n" >> master.lst
/usr/bin/cat ${x} >> master.lst
done

#EOS

Is this what you need?
 
I'll try it at work on monday! Thanks
 
head -n 10000000 *.sql > master.lst

This works because head outputs
==> filename <==
before each file.
 
Thanks a million mate. That worked like a treat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top