Create directories from a sql file?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Create directories from a sql file?
# 1  
Old 02-24-2009
Create directories from a sql file?

Hi,

I have a sql file which has CREATE and INSERT commands in it. Basically, inside this file, a table will be created and the data will be inserted into the table. I was wondering if there is a way for me to create directories from this file?

Thanks in advance
# 2  
Old 02-25-2009
Yes, there is.

Not from within SQL, of course, but another script should be able
to grep the required information from it, and create some directories.

Post the sample data file and any script you're trying to use.
# 3  
Old 02-26-2009
quirkasaurus,

Thanks for your reply. What I would like to do is to take the two sql files and the directory and write a piece of code that reads the two sql files and creates a directory tree.

About the code in one.sql we have a create table file statement plus so many insert to commands and in two.sql we have a create file gallery command with again some insert to.

(which the values will be separated by comma)

Now as my first step, I need to write code to create the directories from "two.sql". Please help me with this.

Thanks in advance!

Last edited by tezarin; 02-26-2009 at 12:41 PM..
# 4  
Old 02-26-2009
if I'm reading you right:

script called "frogs":

Code:
grep 'CREATE TABLE' a.sql |
while read create table gallery junk ; do

  echo mkdir $gallery

done

Run it first to verify that it's doing what you want:

Code:
% frogs

mkdir table_name
mkdir table_name
...


Things look good, run it again like so:

Code:
frogs | ksh

... Then it'll actually make the directories.
# 5  
Old 02-26-2009
quirkasaurus,

Thanks so much, that's exactly what I needed. Can you please let me know if I used your command correctly?

This is what I did: I created a new file and named it frogs. Then, inside it I pasted the code below:

grep 'CREATE TABLE' galleries.sql |
while read create table gallery junk ; do

echo mkdir $gallery

done


I run this file and the result (echo) was exactly as I needed.

So, I run frogs | ksh and one directory gets created.

The thing is galleries.sql was a table so I only got one category. So what I did was I use this program on a database.sql, it'll create the directory AND all the subdirectories.

Thanks again, you've been really helpful, I really appreciate it :-)

Tez

Last edited by tezarin; 02-26-2009 at 12:39 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to create sub directories from specific file extension

In the bash below I am trying to create sub-directories inside a directory from files with specific .bam extensions. There may be more then one $RDIR ing the directory and the .bam file(s) are trimmed (removing the extension and IonCode_0000_) and the result is the folder name that is saved in... (2 Replies)
Discussion started by: cmccabe
2 Replies

2. Shell Programming and Scripting

Help with create multiple directories under diff file systems

Hi, Need help ...I want to create multiple directories in different /file systems using for loop..eg.../ORCL_data01/oradata/orcl/ctl. ../ORCL_data01/oradata/orcl/data. ../ORCL_data01/oradata/orcl/redo. Script :- ========= for dir in `ls -d... (8 Replies)
Discussion started by: Linux6.5
8 Replies

3. Shell Programming and Scripting

Create SQL DML insert statements from file using AWK or similar

Hi all. This is my first post on this forum. I've previously found great help in the huge knowledgebase that is here, but this time I have not been able to find a solution to my problem. I have a large text file that looks like this: typedef struct ABC_struct_nbr1_ { char attr1; /*... (0 Replies)
Discussion started by: Yagi Uda
0 Replies

4. Shell Programming and Scripting

How to create tgz file for all the directories in one time?

Hi, On server there is an one folder . which contains sub folder Eg - TEST folder contains test1, test2, execr ,tt (folder). also includes some text file like abc.txt psp.txt gg.log. here iwant to create tgz file for all the folders and file in one time. I know the command... (1 Reply)
Discussion started by: aish11
1 Replies

5. Shell Programming and Scripting

Create a dummy file in all directories that include a .jpg

Hello. My latest project has me with the need for the following script. Basically, any directory that includes a .jpg file needs to also have a ".picture" file created (if it doesn't exist). Here's an example of what I need. /mnt/user/Pictures/2011/Hawaii - 2011/.picture... (11 Replies)
Discussion started by: Davinator
11 Replies

6. Programming

create a spool file based on values passed from korn shell to sql script

this is my issue. 4 parameters are passed from korn shell to sql script. parameter_1= varchar2 datatype or no value entered my user. parameter_2= number datatype or no value entered my user. parameter_3= number datatype or no value entered my user. parameter_4= number datatype or no... (5 Replies)
Discussion started by: megha2525
5 Replies

7. Shell Programming and Scripting

How can I create a CSV file from PL/Sql in UNIX?

Can someone help me on creating a script that will manage/create a csv file from Pl/Sql using UNIX?Any advice is welcome,thank you so much,:) (2 Replies)
Discussion started by: Atrap
2 Replies

8. Shell Programming and Scripting

To create a file writing a SQL into it from another file

Hi, I have a file in which I have database information along with 1 SELECT statement. Only 1 statement would be there. I want to grep this SELECT STATEMENT only and write into a separate file. Input File format: Database_Name:<database> Schema_Name:<schema> Table_Name:<table> Select *... (3 Replies)
Discussion started by: ustechie
3 Replies

9. Shell Programming and Scripting

check if multiple directories exist else create missing directories

Hi , I 'm trying to check if multiple directories exist on a server, if not create the missing ones and print " creating missing directory. how to write this in a simple script, I have made my code complex if ; then taskStatus="Schema extract directory exists, checking if SQL,Count and... (7 Replies)
Discussion started by: ramky79
7 Replies

10. UNIX for Dummies Questions & Answers

How to create directories

Hi... Can any1 help me by telling me the way to create multiple directories using single command.... to create 1 directory.. mkdir is used.... :D but how to create multiple direcs. like 4 direc. i tried .... $ mkdir a; mkdir b; mkdir c; mkdir d But its 4 commands in a single... (3 Replies)
Discussion started by: abishekmag
3 Replies
Login or Register to Ask a Question