|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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
doneI'm sure there are fancier ways, but something along those lines would get the job done. |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| 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 08:27 PM |
| File comparison in shell script | kiran_j | Shell Programming and Scripting | 3 | 03-10-2011 05:50 AM |
| How to do row comparison in shell script | informsrini | Shell Programming and Scripting | 2 | 09-10-2009 06:38 AM |
| Comparison of 2 sun server patches using script | Sathvik | Shell Programming and Scripting | 1 | 03-21-2009 12:51 PM |
| Help with time comparison shell script for HP-UX | gummysweets | Shell Programming and Scripting | 6 | 10-12-2005 10:48 AM |
|
|