How to create a for loop statement for removing files listed in Oracle table?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to create a for loop statement for removing files listed in Oracle table?
# 1  
Old 08-11-2016
How to create a for loop statement for removing files listed in Oracle table?

Hello Frens,

I am a newbie to shell scripting. I need a help on creating a for loop script (shell script) for removing files. I have a table called a_table with column name fil_name which contains all the files that need to be removed.

Thank you in advance
# 2  
Old 08-11-2016
Hi manisha,

do you have already an sql-query which gets you the files you want to delete? If yes please show the query if possible as a command like it is run directly from the shell. That will be a good starting point to help you.

I don't know how that looks like with oracle. Here is a statement with MySQL:

Code:
echo "SELECT name,phone,mail FROM address;" | mysql DB_NAME

Ideally check the documentation for your oracle-command-line client to leave out any headers, footers and produce output in easy parsable format. This is not required, but makes it easier for you, so you do not have to bother filtering all the superfluous junk out.
# 3  
Old 08-11-2016
Maybe something like (completely untested; be VERY careful when executing!)
Code:
sqlplus user/password 'select "rm " fil_name from a_table;' | sh

# 4  
Old 08-11-2016
Thank you for your reply. My sql query is very simple. select filename from a_table. There are like 45 files, taking that filename, I have to run 'rm' command a shell script.

---------- Post updated at 07:57 PM ---------- Previous update was at 07:55 PM ----------

Thank you for your reply. My SQL query is very simple. select filename from a_table. There are like 45 files, taking that filename, I have to run 'rm' command a shell script. How can I put a for loop in this command?
# 5  
Old 08-12-2016
extract the filename and store in temporary file (/tmp/extracted_file)

Code:
#!/bin/bash
while read filename
do
    echo "removing $filename"
    rm -f ${filename}
done < /tmp/extracted_file

# 6  
Old 08-12-2016
@itKamaraj
Thank you so much. I will try this. Is there any other way to put sql statement to remove the files?
# 7  
Old 08-15-2016
It worked. thank you so muc.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to create the SQLLDR control file from Oracle table.

I need to create the shell script load the few 100 table using the SQLLDR. Need to generate the control file for each table using oracle table. table has "table names" and "column names" using this need create the control file. example table rows below table_nme column_nme DEPT ... (2 Replies)
Discussion started by: pimmit22043
2 Replies

2. Shell Programming and Scripting

Create table within awk-if statement

Hi I am trying to create a table within an awk if statement awk -F, '{ if ($8 ~ /Match/) BEGIN{print "<table>"} {print "<tr>";for(i=1;i<=NF;i++)print "<td>" $i"</td>";print "</tr>"} END{print "</table>"}' SN1.csv | mailx -s "Your details" abc@123.com But this doesnt work.. Please suggest (8 Replies)
Discussion started by: sidnow
8 Replies

3. Shell Programming and Scripting

how to create a loop in an if statement

Hey guys, a=`cat abc | wc -l` b=`cat def | wc -l` if $a== $b then echo "a" else echo "b" fi I want the if condition to retry itself , untill a==b. I can't use goto statemt. Please help. Thanx in advance. Please use next time code tags for your code and data (5 Replies)
Discussion started by: jaituteja
5 Replies

4. UNIX for Dummies Questions & Answers

create table file from different files with index

Hi, I've several files with two collumns, where first collumn can be used as index. filename1 and filename2 how to create a file I should start with cat all files and extract first collumn to create an index? (4 Replies)
Discussion started by: sargotrons
4 Replies

5. Shell Programming and Scripting

Check the record count in table (table in oracle)

I have requirement: 1) Check the record count in table (table in oracle) 2) If records exists generate the file for existing records and wait for some time then Go to sleep mode and Again check the record count after 10 min.......... (Loop this process if record count >0). 3) Generate touch... (1 Reply)
Discussion started by: kamineni
1 Replies

6. Shell Programming and Scripting

Check the record count in table (table in oracle)

I have requirement: 1) Check the record count in table (table in oracle) 2) If records exists generate the file for existing records and wait for some time (Go to sleep mode) and Again check the record count after 10 min.......... (Loop this process if record count >0). 3) Generate touch... (1 Reply)
Discussion started by: kamineni
1 Replies

7. Shell Programming and Scripting

[ORACLE] CREATE TABLE in bash

Hey, I want to create a table in bash, my db server is oracle. You can find my script below: I am very confused. I tried to run this script many times without any luck. Please help! (6 Replies)
Discussion started by: radek
6 Replies

8. HP-UX

to create a oracle table in perl script

Hi all, I have to create table for each month inside a perl script. tablename_monthnameyear. megh_aug2008 for august 2008. megh_sep2008 for september 2008. just like the logfiles created on date basis. thanks megh (1 Reply)
Discussion started by: megh
1 Replies

9. HP-UX

CVSWeb - Directories listed but files not listed

I am using CVSWeb on HPUnix. When i access it, all directories are listed but files are not listed. I am getting the error "NOTE: There are 51 files, but none matches the current tag. " in tomcat sevrer log i am getting the message "rlog warning: Missing revision or branch number after -r"... (0 Replies)
Discussion started by: ganesh
0 Replies
Login or Register to Ask a Question