File Comparision by using Shell Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File Comparision by using Shell Script
# 1  
Old 08-24-2005
File Comparision by using Shell Script

Hello All,

I am trying to find 2 file comparision by using Shell Script. For example, I am having 2 directories namely DAY1 & DAY2. DAY1 directory contains file1.dat, file2.dat, file3.dat, file4.dat, file5.dat & DAY2 directory contains file1.dat, file2.dat, file3.dat, file4.dat, file5.dat. Now, want to compare DAY2/file1.dat with DAY1/file1.dat and store the result in tmp file, .... DAY2/file5.dat with DAY1/file5.dat and store the result in tmp file like. I.e., DAY2/file1.dat first row checkes with each rows in DAY1/file1.dat and so on. How to do in Shell Script. File row length is dynamic and this shell script is to run interactively by using batch jobs in UNIX. Does anybody use this requirement in your project or suggest me how to do this approach. In fact, I am new to UNIX shell scripting.

Regreat your suggestions/help.

Regards
Venkat.
# 2  
Old 08-25-2005
MySQL

Code:
#!/usr/bin/ksh

DIR1=$PATH'/DAY1'
DIR2=$PATH'/DAY2'

for i in `ls -1 $DIR1`
do
#check if same file exists in DIR2 also
filename=`basename $i`
FILE1=$i
FILE2='DIR2/'$filename
diff FILE1 FILE2 > tmp_FILE1_FILE2
done

Modify the peice of code to suit your needs.

Rishi
# 3  
Old 08-31-2005
Hello,

Is there any otherway to find without using DIFF statement?

Regards,
Venkat
# 4  
Old 08-31-2005
MySQL

you can use "cmp" if diff is not to your taste Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX and Linux Applications

Unix Shell Scripting : Comparision of two files

Hi, We need to compare a text file File1.txt and config file File2.txt in a way that it checks if the content of File1.txt exists between the range mentioned in File2.cfg. The range here is the range between col1 and col2 of File2.cfg If the content of File1.txt lies between the range of... (12 Replies)
Discussion started by: CFA
12 Replies

2. Shell Programming and Scripting

Array comparision in bash shell

I'm not sure if i can put the problem in understandable form.Let me try: I have a array which is like and always fixed: Array1=(new inprogress pending Restored Resolved ) Other 2 array array2 which may varry but always subset of above array: Like it can be : Array2=(New inprogress... (2 Replies)
Discussion started by: InduInduIndu
2 Replies

3. Shell Programming and Scripting

File Comparision

Hi All, I want to write a script which will compare two files and tell me if the files are different. Actually my files will be same but order of lines will be different,so diff is not working. I have written a script to do this:- while read line; do cnt=`grep -i $line... (6 Replies)
Discussion started by: prasson_ibm
6 Replies

4. Shell Programming and Scripting

File comparision

Hi All I have to files cat a.txt AAA BBB CCC DDD and cat b.txt AAA CCC EEE i want to compare these two files and o/p should have content of file a.txt which is not in file b.txt c.txt BBB DDD Please help me (3 Replies)
Discussion started by: aaysa123
3 Replies

5. Shell Programming and Scripting

File comparision

Hi All I have to files cat a.txt AAA BBB CCC DDD and cat b.txt AAA CCC EEE i want to compare these two files and o/p should have content of file a.txt which is not in file b.txt c.txt BBB DDD Please help me (1 Reply)
Discussion started by: aaysa123
1 Replies

6. Shell Programming and Scripting

File comparision

HI, I would like to know how to compare two files and replace non-matching lines with "_" . I can get non-mathing lines with grep -v -f file1 file2 i just want to knw how to display 'file2' with non-matching lines from 'file1' replaced by "_" for exmaple file1: a b c d ... (2 Replies)
Discussion started by: maddy81
2 Replies

7. UNIX for Dummies Questions & Answers

File comparision and modification using shell script

Hello everyone, I would like to know how to compare two files and modify any differences with some other data using shell script. I think it would be better understood with an example. I got two files named 'filex' and filey'. 'filex' is constant file without any changes in data. 'filey' is... (2 Replies)
Discussion started by: maddy81
2 Replies

8. Shell Programming and Scripting

file size comparision local file and remote file

Hi, I have written a script which would FTP a dump file to the FTP server and log the whole activity into a file. to confirm the success of the file copy i grep for "226 file receive OK" and then send out an email saying success. Now i want to make sure the bytes of the local file and... (4 Replies)
Discussion started by: dba.admin2008
4 Replies

9. Shell Programming and Scripting

error while doing decimal comparision in shell

a=10 b=10.6 c=$(echo "$a - $b" | bc) if ] echo "success" else echo "failure" fi while executing the above sample code, am getting the below error: seems unix is comparing .6 with 0 instead of 0.6 with 0. can anyone help me in solving this ? regards, (7 Replies)
Discussion started by: cmaroju
7 Replies

10. Shell Programming and Scripting

String comparision in shell scripting

Hi Guys, I am new to scripting I have written a code to compare strings,but I am getting some Exception Code snippet: MODE="D" if ]; then . $file1 fi Error: ./BatchJobs.sh: [[: execute permission denied I have given all Execute permissions to the script(chmod 755... (2 Replies)
Discussion started by: Anji
2 Replies
Login or Register to Ask a Question