Need some help on scripting for validating the files before loading


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need some help on scripting for validating the files before loading
# 1  
Old 02-13-2012
Need some help on scripting for validating the files before loading

Hi,

I need to perform some validation steps on the files before I start loading them.

1. I need to check for the availabilty of the file in expected path with expected name.
2. I need to check If the file format is correct.
a. confirm if correct delimiter is used.
b. confirm name, number and order of the columns.

Filename: SDsheet.csv
Delimiter used: ";"
10 columns are used with the name and order A,C,D,F,K,M,O,R,S,U.

Can anyone please help me how to validate these steps before I process to load the file.

Thanks in advance..
# 2  
Old 02-13-2012
1. Assuming the file extension is csv
Code:
if [ "${filename##*.}" != "csv" ]; then
  echo "$filename extension is not .csv"
  exit 1
fi
if [ !-r $filename ]; then
  echo "$filename does not exist or readable"
  exit 1
fi


Delimiter
Code:
awk -F";" 'NF!=10{exit(1)}' $filename
if [ $? -eq 1 ]; then
  echo "$filename does not contain 10 records in each row"
  exit 1

As for the "confirm name, number and order of the columns.", pls elaborate with examples.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

When loading Linux "loading please wait.." then nothing?

Hi everyone, I have a problem but I have never installed a separate OS before so my lingo and understanding may not be as good as some of you. I will try and explain my problem best I can. I am trying to instead of loading Windows 7 when my computer starts up, for it to start linux specifically... (2 Replies)
Discussion started by: markhow30
2 Replies

2. Shell Programming and Scripting

Validating files using server name and directory

Hi, I want to check if a file is a regular file or not using server name and file path. Example: I want to check whether //<server_name>/home/chandan/abc.txt is a regular file or not. Need your help!!. Thanks (3 Replies)
Discussion started by: ChandanN
3 Replies

3. UNIX for Advanced & Expert Users

Help with loading config files

Hi All, I'm bit confused with a script Any help would be appreciated I have a config file say config.cfg and iam loading config file in My_Script.sh..The script name is My_Script.sh. My_Script.sh and config.cfg are in same directory...My_Script.sh is run on the crontab 50 01 * * * &&... (2 Replies)
Discussion started by: selvam
2 Replies

4. UNIX for Advanced & Expert Users

Loading files incrementaly

Hi Am trying to sftp this way UnixBoxA----->UnixBoxB My code will run on UnixBoxB, it will make a secure connection and pull the files from UnixBoxA. Apart from that I do not have any access on UnixBoxA Now UnixBoxA will receive the files daily, the file format will be... (0 Replies)
Discussion started by: hemanty4u
0 Replies

5. Shell Programming and Scripting

Validating IP address.

Hi All, This is a small snippet that I am using to validate the format of IP address.This is working fine. Since this is not elegant, please let me know if anyone has a better working code than the one below. Also I am planning to ping the ip address given by the user and check the $?... (3 Replies)
Discussion started by: nua7
3 Replies

6. Shell Programming and Scripting

loading Binary files with SQLLDR

Hi, Can anyonr please tell how to load a binary file through SQLLDR. I have the structure of the binary file in a seperate lb file but I don't know how to feed it to the sqlldr. (0 Replies)
Discussion started by: snowline84
0 Replies

7. Shell Programming and Scripting

Function loading in a shell scripting like class loading in java

Like class loader in java, can we make a function loader in shell script, for this can someone throw some light on how internally bash runs a shell script , what happenes in runtime ... thanks in advance.. (1 Reply)
Discussion started by: mpsc_sela
1 Replies

8. Shell Programming and Scripting

validating 10. IP address any way possible

HELP: validating IP addresses any way possible -------------------------------------------------------------------------------- I am trying to validate input from the user in a script. I thought is was easy to do using regular expressions but I can't figure out how to use REs in a... (1 Reply)
Discussion started by: nrodolfich
1 Replies

9. Shell Programming and Scripting

Validating $1 and $2 before using

Hi there, I'm trying to validate my $1 and $2 before I use them in the sqlplus update, I think I have the validation rules set correctly??? however when I test my script, it jumps straight into the sql. It doesn't seem to validate the vars....even when I know they are incorrect. if ; then ... (6 Replies)
Discussion started by: nhatch
6 Replies

10. Shell Programming and Scripting

validating dates

This is what I have to check date entries in an interactive script with the end users... I use this to build control cards for a reporting utility supplied by a software vendor. I also want to check to make sure its a valid day based on the month (ie 30days has sept, april, june and Nov..)... ... (2 Replies)
Discussion started by: MizzGail
2 Replies
Login or Register to Ask a Question