Shell script in SH

Hi all,
I am new in this field
I need to write a script to read a data from txt file.My file contains data in the form of many lines.I need to read the lines which contains "alter table table_name add" then need to pick the table name from this and search for that in database.If it exists then need to pick the columns which is to be added. and perform the given query .Can anybody help me with writing the script.
Please reply me ASAP.

Thanks

Your requirements are several.

To get anywhere, we need to know/see a lot of things:

first: what db?

second: a sample of the input file with an alter table line

third: your expected output from that input file - I guess a table name

fourth: how do you propose to determine the fields you need to add?

hi
MY requirments are:
1.to read data from a txt file which i had transferred to UNIX using FTP.
for eg: my file contains many lines of data like "alter table tablename add(column name)".
2.Now i want to read the table names where we are adding the columns.
3.after reading the table name i need to check the existence of that table in my database.**I have done this part.
4.if table exists then i need to read the column names which has to be added in table and add them.

my first and foremost problem is how i read the table name where we are required to add the columns.

please help me with the codes.

---------- Post updated at 03:26 AM ---------- Previous update was at 03:25 AM ----------

the fields are not separated in my txt file.

Hi
To get a fair idea of using accessing sql from shell, u can check this link: connect to sql

Regarding to get the fields for a given table, you can do something like this:

$ cat col.sh
#!/usr/bin/ksh

x=`sqlplus -s scott/tiger@school  <<EOF
set heading off
spool result.txt
desc $1;
spool off
EOF`

head -1 result.txt | grep -q ERROR

if [ $? -eq 0 ]; then
   echo Invalid table $1
 else
      echo "Table cols of $1"
      awk 'NR>2{print $1}' result.txt
 fi

Run this:

#./col.sh table_name

Guru.

hi guru
i have no problem in sql part .the only problem is to read data from the file.i need to extract all the table names between alter table and add.there is no field separation it's a single string.

Hi Alisha
Providing a sample file would have made it a bit easier.

Try this:

Assuming a sample file:

# cat infile
alter table ABC add(....)
alter table XYZ add(....)

To get table list:

#sed 's/\(alter table \)\(.*\)\(add.*\)/\2/' infile
ABC
XYZ

Guru.

thanks a lot for the help.
can we do it using awk.

Try this:

# awk '/alter table/{print $3}' infile
ABC
XYZ

Guru.

i have tried that earlier but its a single string fields are not seperated.
one more thing by using sed command i can store the extracted table names in new file by using redirection operator.