Validate before moving files.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Validate before moving files.
# 1  
Old 09-20-2010
Validate before moving files.

HTML Code:
File Format
dataline1,12,,,,;
dataline2,24,,,;
dataline3,12,,,,;
dataline4,24,,,;
COUNT=0004;
Hi,

I have source(/home/rgupta) and destination folders /home/rgupta/arch and /home/rgupta/err. Source folders has many files. I want to move the files from source to destination with some validations.

All files have trailer records contains the count of data line records.As in the above files there there are four records and trialer has count of this (COUNT=0004).

So, before moving to files, this should be validated that count given in the trailer record is same as tolal number of dataline records (wc -l -1).
If the trailer record count = wc -l -1 then files should be moved to /home/rgupta/arch otherwise these should be moved to /home/rgupta/err.

Thanks for help in advance.
# 2  
Old 09-20-2010
Code:
#!/bin/bash
cd /home/rgupta
for F in *   # to scan all files in directory
do
   eval $(tail -1 "$F")
   # evaluates the last line : executes the command COUNT=0004; so it sets COUNT to '0004;'
   if [ "$(grep -c dataline "$F")" = "$(printf '%d\n' $COUNT)" ]
   # grep -c counts the # of lines containing 'dataline' . The printf is used to convert '0004;' to '4'
   then   mv $F arch/
   else   mv $F err/
   fi
done


Last edited by frans; 09-20-2010 at 01:56 PM.. Reason: added comments
This User Gave Thanks to frans For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Validate compressed files

Hi All, I have zip file that needs to be validated and checked for 5 times with sleep of 60 seconds. Some thing like below #!/bin/bash counter=1 while do curl -i -k -X GET `strings tmp.txt |grep Location| cut -f2 -d" "` -H "Authorization: Token $TOKEN" -o $zip_file ## this is... (6 Replies)
Discussion started by: Master_Mind
6 Replies

2. Shell Programming and Scripting

awk to compare files and validate order of headers

The below awk verifies the count and order of each text file in the directory. The script does execute and produce output, however the order of the headers are not compared to key. The portion in bold is supposed to do that. If the order of the headers in each text file is the same as key, then... (0 Replies)
Discussion started by: cmccabe
0 Replies

3. Shell Programming and Scripting

Validate input files daily

We have a job which we need to run on daily bases, before loading data in a table we need to validate whether the input file is received or not. Daily client will place the files in a particular path.Below files which I need to process for 04/01/2013(Load date).... (2 Replies)
Discussion started by: katakamvivek
2 Replies

4. Shell Programming and Scripting

Validate input files and update

We have a job which we need to run on daily bases, before loading data in a table we need to validate whether the input file is received or not.Inputfile formatsrc_sps_d_Call_Center_Reporting_yyyymmdd_01.dat SPS-Service nameYYYY-yearMM-MonthDD-dayLike above we will get n number of files for... (1 Reply)
Discussion started by: katakamvivek
1 Replies

5. Shell Programming and Scripting

[Validate] Script to remove files olderthan X days

Hi, I have written a small shell script to remove the files olderthan X days (say 30). But I not sure how it acts on the filesystem, as I am using rm. if then echo "##############################################" echo "Invalid no .of arguments\n" echo "Usage:\n$0 PATH... (6 Replies)
Discussion started by: karumudi7
6 Replies

6. Shell Programming and Scripting

Finding files with wc -l results = 1 then moving the files to another folder

Hi guys can you please help me with a script to find files with one row/1 line of content then move the file to another directory my script below runs but nothing happens to the files....Alternatively Ca I get a script to find the *.csv files with "wc -1" results = 1 then create a list of those... (5 Replies)
Discussion started by: Dj Moi
5 Replies

7. Shell Programming and Scripting

How to validate files after FTP

Hi, I have to write a script and the requirment where using ftp i need to get 8 files from a remote box to local. I know how how to ftp and do get. However i want do a validation after get. After geting for 8 files, i want to compare the size of the 8 files when it was in remote box with size... (6 Replies)
Discussion started by: tarakant
6 Replies

8. Shell Programming and Scripting

Help needed to validate and merge Two files

Hi.. I am new to unix !!! Please help me in combining two files by validating the first column. The files are tab limited !!! I have a file which has the following contents... DEPT1_BABYCARE 20 abce DEPT2_PHARMACY 50 cdgde DEPT3_WOMENS ... (7 Replies)
Discussion started by: ashokrajaa
7 Replies

9. Shell Programming and Scripting

sftp validate files before removal

I have a shell, which locks calls an expect script that connects to an sftp and downloads all files. I need it to then check each file in my directory and compare the sizes. If the file name and file size match, then delete the file on the server. Is this possible? :confused: (2 Replies)
Discussion started by: tariqjamal
2 Replies

10. Shell Programming and Scripting

sftp shell that will validate files

Hi. I've written a shell that will sftp about 5,000 to 10,000 files a day (they are small 200 byte files). Where I'm stuck at is that I need to not only copy those files from the ftp server, I also need to delete the files on the ftp server after they have been ftped BUT before they've been... (0 Replies)
Discussion started by: biglarrrr
0 Replies
Login or Register to Ask a Question