The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
file comparison...help needed. er_ashu UNIX for Dummies Questions & Answers 4 05-15-2008 06:37 PM
File Comparison net_shree Shell Programming and Scripting 19 01-10-2008 04:00 PM
Problem in ksh script ( String comparison ) amarnath AIX 1 07-18-2006 03:40 AM
Problem in ksh script ( String comparison ) amarnath Shell Programming and Scripting 3 07-13-2006 09:14 AM
Help with time comparison shell script for HP-UX gummysweets Shell Programming and Scripting 6 10-12-2005 07:48 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-29-2008
Registered User
 

Join Date: Nov 2005
Posts: 22
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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 01-30-2008
Registered User
 

Join Date: May 2007
Posts: 104
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.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:22 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0