Shell script to find specific file name and load data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to find specific file name and load data
# 1  
Old 02-15-2011
Shell script to find specific file name and load data

I need help as to how to write a script in Unix for the following:
We have 3 servers;

Quote:
Server A is the database server
Server B is the Application Server
Server C is the Reference server, where the files gets loaded.
The mainframe will FTP them to a folder. In that folder we will need the script to look and see if the specific file name is there and load it to the correct table.
Quote:
Table A has File1, File2, File3
Table B has File 4, File5, File6
.
.
.
Can anyone pls help me out with this...
Thanks
# 2  
Old 02-15-2011
If you have bash shell you could try something like this:

Code:
#!/bin/bash
FOLDER=./folder
TABLEA="File1|File2|File3"
TABLEB="File 4|File5|File6"
cd $FOLDER
shopt -s extglob
for file in *
do
    case $file in
       @($TABLEA))
           echo "Load $file into table A"
           # Process file here
       ;;  
       @($TABLEB))
           echo "Load $file into table B"
           # Process file here
       ;;  
    esac
done


eg:
Code:
$ ls folder
File 4  File1  File6

$ ./doload.sh
Load File 4 into table B
Load File1 into table A
Load File6 into table B

# 3  
Old 02-16-2011
And if you have bash 4.0 you can use associative arrays:

Code:
FOLDER=./folder
declare -A proc
proc=( [File1]="A" [File2]="A" [File3]="A"
       [File 4]="B" [File5]="B" [File6]="B" )
cd $FOLDER
for file in *
do
   if [[ ${proc[$file]} ]]
   then
       echo "Load $file into table ${proc[$file]}"
       # Process file here
   fi
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Write a shell script for SQL loader to load data into a staging table

Hi, I'm new to Linux. I'm working on a database, and need to load data in a database table (which I already created) using shell script. The table has two columns - Acct_number (not nullable) and date (timestamp). I'm not able to write a shell script for that. Can any one help me? ... (3 Replies)
Discussion started by: saisudeep
3 Replies

2. Shell Programming and Scripting

How to read file and load data into a script as variable

I need to read a text file that contain columns of data, i need to read 1st column as a function to call, and others are the data i need to get into a ksh script. I am quite new to ksh scripting, i am not very sure how to read each row line by line and the data in each columns of that line, set... (3 Replies)
Discussion started by: gavin_L
3 Replies

3. Shell Programming and Scripting

why do we need UNIX shell script to load data into Oracle database

Hello everyone, I am new to shell scripting/ loading data into a database. I want to load data into Oracle database using SQL loader. Can some one please explain why do we need unix shell script to load the data into the database? Also can someone please explain what has to be in that script?... (5 Replies)
Discussion started by: new_prog
5 Replies

4. Shell Programming and Scripting

Perl script to Archive the data file after the load

I have written a perl scripts which loads the data. Now i want to modify the script, to Archive the Input file after the successful load of data. Can anyone please share it and help me .... Thanks. (2 Replies)
Discussion started by: msrahman
2 Replies

5. Shell Programming and Scripting

Korn/bash Script to monitor a file a check for specific data

Hi, Im trying to write this script but im stuck on it, basicaly what i want to do is to write a code to verify a log file ( apache log file for example ) and for each new line with specific data , then, output this new line for another file: full ex: output of the server.log is (... (4 Replies)
Discussion started by: Thales.Claro
4 Replies

6. Shell Programming and Scripting

C Shell problem: using a key from one file to find data in another

I've never written scripts (just switched from Ada to C++). I have a book that's over my head and a few examples, other then that I'm floundering. Everything here at work is being done in C Shell. None of the C++ programmers are experienced in shell scripting. I have a data file with the... (2 Replies)
Discussion started by: bassmaster
2 Replies

7. Shell Programming and Scripting

Simple shell script to find and print data

Hi, I have a log file containing data on emails sent. Looks a bit like this for one email: Content-Type: text/plain; charset="UTF-8" Date: 12 Jun 2008 14:04:59 +0100 From: from@email.com Subject: xcf4564xzcv To: recip@email.co.uk Size = 364 Jun 12 14:04 smtp_234sldfh.tmp I need to... (5 Replies)
Discussion started by: terry2009
5 Replies

8. Web Development

script to load data from csv file

hello i want a script to load the data line by line from a csv file into a mysql table (3 Replies)
Discussion started by: srpa01red
3 Replies

9. Shell Programming and Scripting

shell script to read data from text file and to load it into a table in TOAD

Hi....can you guys help me out in this script?? Below is a portion text file and it contains these: GEF001 000093625 MKL002510 000001 000000 000000 000000 000000 000000 000001 GEF001 000093625 MKL003604 000001 000000 000000 000000 000000 000000 000001 GEF001 000093625 MKL005675 000001... (1 Reply)
Discussion started by: pallavishetty
1 Replies

10. Shell Programming and Scripting

Shell Script to Load data into the database using a .csv file and .ctl file

Since i'm new to scripting i'm findind it difficult to code a script. The script has to be an executable with 2 paramters passed to it.The Parameters are 1. The Control file name(.ctl file) 2. The Data file name(.csv file) Does anybody have an idea about it? :confused: (3 Replies)
Discussion started by: Csmani
3 Replies
Login or Register to Ask a Question