file comparison script | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

file comparison script

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-30-2008
tiger99 tiger99 is offline
Registered User
 
Join Date: Nov 2005
Last Activity: 13 April 2008, 1:31 PM EDT
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
file comparison script

Hi
I need to write a script that can check files in a folder one by one and compare against a fixed file.

i.e.
I have some files in folder_a
file1.txt
file2.txt
file3.txt
and a fixed file in folder_b
fixed.txt

Inside the fixed.txt, I have
line1.sql
line2.sql
line3.sql

Inside the file1.txt, I have
line1.sql
Inside the file2.txt, I have
line2.sql
Inside the file3.txt, I have
line3.sql

I was wondering, how can I write a script that would check file1.txt to file3.txt and make sure that fixed.txt has everthing in those three files?

I start by searching the files in folder_a like the following...then I am not sure what to do next



Code:
find ~/Documents/folder_a -name 'file*.txt'

Could someone please give me some guidence/help on how to go about solving this
Sponsored Links
    #2  
Old 01-30-2008
earnstaf earnstaf is offline
Registered User
 
Join Date: May 2007
Last Activity: 15 November 2012, 10:53 PM EST
Posts: 113
Thanks: 0
Thanked 0 Times in 0 Posts

Code:
for file in `ls folder_a`
do
cat $file | while read line
do
grep -q $line folder_b/fixed.txt
if [ $? -eq 1 ]; then
     echo "$file - $line not in fixed.txt"
     echo "$line" >> folder_b/fixed.txt
fi
done
done

I'm sure there are fancier ways, but something along those lines would get the job done.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Korn shell script comparison vani123 Shell Programming and Scripting 1 03-14-2011 09:27 PM
File comparison in shell script kiran_j Shell Programming and Scripting 3 03-10-2011 06:50 AM
How to do row comparison in shell script informsrini Shell Programming and Scripting 2 09-10-2009 07:38 AM
Comparison of 2 sun server patches using script Sathvik Shell Programming and Scripting 1 03-21-2009 01:51 PM
Help with time comparison shell script for HP-UX gummysweets Shell Programming and Scripting 6 10-12-2005 11:48 AM



All times are GMT -4. The time now is 11:03 AM.