Validation before moving the File


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Validation before moving the File
# 1  
Old 10-21-2014
Validation before moving the File

Hi,

Before moving the files from source directory to target directory I need to check if the files have these strings 'Error', 'Not Valid' ,' YTF-' or if the file is a zero byte file, if the file contains these strings or if it is a zero byte file i should log a entry in the log file and fail the script.

Please suggest how can I acheive this.

Regards,
Deepti
# 2  
Old 10-21-2014
Hello Deepti,

Following may help you, I didn't test it though, kindly try it and let me know if this helps.
Code:
VALUE=`awk '/Error/ || /Not valid/ || /YTF-/ {print $0}' filename`
if [[ -n $VALUE || ! -f filename ]]
then
      echo "ERROR found in file." >> LOG_ENTRY_FILE
else
      mv filename(which we need to move) target_path
fi

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 10-21-2014
1. You need to learn how to use and manipulate the grep command to search for specific patterns in a file (or input string).
2. To check if the file size is zero, you can use the test command or the [ expression ]. Here's a wiki link with simple examples to get you started.

Please also let us know what you have tried.
This User Gave Thanks to balajesuri For This Post:
# 4  
Old 10-22-2014
Thanks Ravinder, can you please help me know how can I automate this to check for all the files in a particular folder.

Code:
find /src/var/ -name '*.txt' | while read file
VALUE=`awk '/Error/ || /Not valid/ || /YTF-/ {print $0}' $file`
if [[ -n $VALUE || ! -f $file ]]
then
      echo "ERROR found in file." >> LOG_ENTRY_FILE
else
      mv filename(which we need to move) target_path
fi

I tried to use the above code, but it's not working for the dynamic files.

Regards,
Deepti
# 5  
Old 10-22-2014
Quote:
Originally Posted by gaur.deepti
Thanks Ravinder, can you please help me know how can I automate this to check for all the files in a particular folder.

Code:
find /src/var/ -name '*.txt' | while read file
VALUE=`awk '/Error/ || /Not valid/ || /YTF-/ {print $0}' $file`
if [[ -n $VALUE || ! -f $file ]]
then
      echo "ERROR found in file." >> LOG_ENTRY_FILE
else
      mv filename(which we need to move) target_path
fi

I tried to use the above code, but it's not working for the dynamic files.

Regards,
Deepti
Hello Deepti,

You can do the following in same. Not tested though.

Code:
target_path="/src/test"                     ##### Asssuming there is test directory in src you can set as per your need 
find /src/var/ -name '*.txt'  > File_names
while read line
VALUE=`awk '/Error/ || /Not valid/ || /YTF-/ {print $0}' $line`
if [[ -n $VALUE || ! -f $file ]]
then
      echo "ERROR found in file." >> LOG_ENTRY_FILE
else
      mv $line(which we need to move) target_path
fi < "File_names"

Thanks,
R. Singh

Last edited by RavinderSingh13; 10-22-2014 at 05:51 AM..
# 6  
Old 10-22-2014
How about
Code:
while read FN; do grep -ELi "Error|Not valid|YTF-" $FN; done <FileNames | while read CF; do echo mv $CF somewhere; done

Remove echo if happy with the result. For non-moved files reverse the grep action.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Flat File Validation

Hi Team there is a requirement to do validate on Flat files using Shell Scripting. Suppose we have two flat files ( F1, F2). Validation 1. Row count between F1 and F2 a) Write it in a file with results of count of each file and differences if any 2. Apply checksum or any... (1 Reply)
Discussion started by: shlearner
1 Replies

2. Shell Programming and Scripting

File validation

Hi there, As a part of file validation, I needed to check for delimiter count in the file. My aim is to find, how many records have failed to have predefined numbers of delimiters in the file. My code looks like below i=`awk -F '|' 'NF != 2 {print NR, $0} ' ${pinb_fldr}/${pfile}DAT |... (3 Replies)
Discussion started by: anandapani
3 Replies

3. Shell Programming and Scripting

XML file validation

Hi, i am new to unix script. i have two xml files. one is orderinfo.xml and another one is xsd file(EmailMessage.xml). we need to compare the both file for poper nodes exists are not. for example: <xsd:element name="EmailMessage"> tag in the EmailMessage.xml file(xsd sheet),this tag... (2 Replies)
Discussion started by: bmk
2 Replies

4. Shell Programming and Scripting

File validation

Hello, File contains 1,3 and 5 are required columns. it's working use this command. awk -F\| '$1 && $3 && $5' test1.txt > test2.txt How can use this unix programming.while using runnign this scirpt,it's raising the error. awk: ^ syntax error #!/usr/bin/ksh `awk -F\| '$1 &&... (3 Replies)
Discussion started by: bammidi
3 Replies

5. Shell Programming and Scripting

File Name Validation

Hi All, I am trying to validate the file name against the naming convention mentioned in configuration file. In the configuration file, the file name convention is mentioned as: Myfile_SQ<NN>_<NN>_YYYYMMDD_HHMMSS.xml The actual file received is Myfile_SQ10_30_20110423_073002.xml How do... (1 Reply)
Discussion started by: angshuman
1 Replies

6. Shell Programming and Scripting

File and Data Validation.

Hello, I am working on an interface between a legacy system and an ERP system.The format of the data extracted into the staging folder from the legacy system is a follows. One control file named ExtractDataControl.txt Multiple entity files eg R1001.txt, R1002.txt, R1020.txt The control... (5 Replies)
Discussion started by: Savio_Saldanha
5 Replies

7. Shell Programming and Scripting

File name and format validation

Hi Gurus, I used unix long time back. I need help for writing a unix script which can be automated and execute every day on specific time. 1.) This is the actual functional requirement. Informatica should reject incoming files that have invalid filenames or file formats 2.) My File... (6 Replies)
Discussion started by: vsmeruga
6 Replies

8. UNIX for Dummies Questions & Answers

File Validation

Hi All, I am new to UNIX scripting. I need to validate a file. I need to check whether the file has a header , detail records and footer. If all the file is good I need to create a status file with the status 'Y' else 'N'. I have pasted the an example of the file below: ... (5 Replies)
Discussion started by: kumar66
5 Replies

9. UNIX for Advanced & Expert Users

Unix File Validation! Help

Hi All, I got a file with 3 fields delimited by hyphen "-". I have to validate & cleanse the data before i begine the processing Requirements 1. No record should contain more than 2 delimiters 2. No record should even contain less than 2 delimiters 3. Any records that matches rule 1 &... (3 Replies)
Discussion started by: minnuverma
3 Replies

10. Shell Programming and Scripting

validation :file <filename>

My user is ftp a CSV file from window. There is possiblity to doing FTP through different mode. This file is then picked by another program, but I want to make sure the FTP file would be always ascii format, bu releasing a commaon File <file name> Can any one provide input , abut how to put a... (2 Replies)
Discussion started by: u263066
2 Replies
Login or Register to Ask a Question