Validate the file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Validate the file
# 1  
Old 05-25-2010
Validate the file

How do we validate the header file. The file number should increament by 1 (position 17 to 19) if not abend the process.

first week
ABC0001 20100101123

second week
ABC0001 20100108124

Third week
ABC0001 20100115125
# 2  
Old 05-25-2010
Hello,

You can extract file number (position 17-19) using cut command below
Quote:
cut -c 18-19
I am not sure how your file names would be. For eg if you want to check this for list of files in a directory etc.

-Nithin.
# 3  
Old 05-25-2010
I think i didnt give clear picture on wht i needed. My req is like

Assume that source file is available on every week say test_file.dat

1. Get the previous file number in temp file (something like cut -c 17-19)
2. Compare current file number with previous week file number
3. If file number is incremented by one then process that file if not abend the process
# 4  
Old 05-25-2010
Code:
#!/bin/sh

CURWEEK=`echo "ABC0001 20100115125" | cut -c18-19`
LASTWEEK=`echo "ABC0001 20100108124" | cut -c18-19`

if [ $CURWEEK -gt $LASTWEEK ];then
	#Run your program
fi

# 5  
Old 05-25-2010
diff of CURWEEK & LASTWEEK should be 1
# 6  
Old 05-25-2010
Hope this works
Code:
#!/bin/sh

CURWEEK=`echo "ABC0001 20100115124" | cut -c18-19`
LASTWEEK=`echo "ABC0001 20100108125" | cut -c18-19`

if [ `echo "$CURWEEK - $LASTWEEK" | bc` -eq 1 ];then
# Your program
fi

-Nithin
# 7  
Old 05-25-2010
As OP said in his post, the file will be created in an incremental basis and we can not hard code the file-name for comparing with the last file.

the number of the last file must be picked from some temp file each time I think so.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Validate csv file

Hi guys, i want to validate the no.of colums in a csv file ,but if there is a comma(,) in any of the data values it should skip and count only valid (,) commas. e.g 1.abc,pqrs,1234,567,hhh result :4 2.abc,pqrs,1234,567,hhh,"in,valid",end12 result:6 here script should skip the comma inside... (10 Replies)
Discussion started by: harry123
10 Replies

2. Shell Programming and Scripting

what is the better way to validate records in a file.

hi all, We are checking for the delimited file records validation Delimited file will have data like this: Aaaa|sdfhxfgh|sdgjhxfgjh|sdgjsdg|sgdjsg| Aaaa|sdfhxfgh|sdgjhxfgjh|sdgjsdg|sgdjsg| Aaaa|sdfhxfgh|sdgjhxfgjh|sdgjsdg|sgdjsg| Aaaa|sdfhxfgh|sdgjhxfgjh|sdgjsdg|sgdjsg| So we are... (4 Replies)
Discussion started by: Seshendranath
4 Replies

3. Shell Programming and Scripting

Need script to validate file according to date

Hi All, I am very new to unix and just started to work with unix and shell scripting.I have a query anyone help would be much appreciated I am using sun solaris OS I want to validate a file according to its date and if validate successful then it would write the file name,size,date and... (3 Replies)
Discussion started by: sv0081493
3 Replies

4. Shell Programming and Scripting

validate tar file on tape

I've got a KSH/AIX question that I haven't been able to figure out yet. I've got a tape archive program that "tar's" data to a tape. After creating the archive, I'd like to somehow verify that the tape is actually good. So, what I'd like to do as a simple "sanity" check that I can read the tape... (9 Replies)
Discussion started by: dernsdorff
9 Replies

5. Shell Programming and Scripting

Validate Zip file

Hi all, How to check if the input file is zip file, If yes, validate the version of gzip utility (1 Reply)
Discussion started by: balaji23_d
1 Replies

6. Shell Programming and Scripting

Better way to Validate column data in file.

I am trying to validate the third column in a pipe delimited file. The column must be 10 char long and all digits 0-9. I am writing out two new files from the existing file, if it would be quicker, I could leave the bad rows in the file and ignore them in the next process. What I have is... (12 Replies)
Discussion started by: barry1
12 Replies

7. Shell Programming and Scripting

validate against a file

Hello all, I am having problem in writing a if condition for the following: I have a file Instance.dat which has: #Server Environment server1 dev server2 dev server3 sit #!/bin/ksh ENV=dev for i in $( cat Instances.dat | grep -v '#' |awk {'print $2'} ) do if ]... (7 Replies)
Discussion started by: chiru_h
7 Replies

8. Shell Programming and Scripting

How to validate a CSV file?

Hi. I think some people have already asked this, but the answers/questions seem to be about validating the contents inside a CSV file. I am simply after a simple variable solution (ie 0 = false, 1 = true) that I can use in my script to say that file so-and-so is actually a CSV file, or in some... (4 Replies)
Discussion started by: ElCaito
4 Replies

9. Shell Programming and Scripting

validate csv file load

Hi All, I am using sqlldr to load my csv files into the database. The code in the sh script is as follows. sqlldr ${DBUSER}/${DBPASS}@${ORACLE_SID} \ data=myCSV.data \ bad=myCSV.bad \ control=myCSV.ctl \ ... (0 Replies)
Discussion started by: rahulrathod
0 Replies

10. Shell Programming and Scripting

validate the file name

write a shell script that check file name like pstat_24.txt (up to 5 digits) i mean to say this digit can be range from 1 to 99999 only correct file name are pstat_10000.txt pstat_12345.txt pstat_14569.txt wrong file name are pstat_1234567.txt pstat_1a2345.txt... (2 Replies)
Discussion started by: maykap100
2 Replies
Login or Register to Ask a Question