The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
comparing PID values of 2 Files in shell Options marconi Shell Programming and Scripting 2 12-19-2007 12:02 PM
Comparing two files.. padarthy Shell Programming and Scripting 1 08-29-2007 08:01 AM
comparing shadow files with real files terrym UNIX for Advanced & Expert Users 4 02-09-2007 01:38 AM
Script error.. for comparing 2 files! gkrishnag UNIX for Advanced & Expert Users 4 09-13-2006 09:19 AM
shell script comparing files in a file raina_nalin Shell Programming and Scripting 4 06-21-2005 06:00 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-18-2008
Registered User
 

Join Date: Jun 2008
Posts: 2
shell script for comparing 2 files

Hi,

how to read the 2 files and compare each other in shell script? i have 2 files test1 and test2, both files contains 20 character records.we have to compare file 1 records with file2, if exists then reject the record else we have to append it to test2 file. in file test1 around 100 single column records are there. and test2 around 50000 single column records.

how can we do in shell script?

ex: test1
burningburning21sstt
ex:test2
burningburning21eett

we need to compare only first 16 letters of the record like
if test1.burningburning21 = test2.burningburning21 then reject.


Thanks in advance
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-20-2008
Registered User
 

Join Date: May 2008
Location: India
Posts: 34
Have you tried
Code:
$ diff filename1 filename2
?

You might need to write a script to loop all the contents in a file if there is any change.
Reply With Quote
  #3 (permalink)  
Old 06-20-2008
Registered User
 

Join Date: Feb 2008
Posts: 34
Hi,
Try the below script. Customize, if required


for line in `cat test1.lst|cut -c1-16`
do
grep -i $line test2.lst >/dev/null
exitcode=$?
if [ $exitcode = 0 ]; then
echo "$line : String Exists"
else
echo "String does not exists, hence appending in test2 file"
echo $line >> test2.lst
fi
done
Reply With Quote
Google The UNIX and Linux Forums
Reply

Bookmarks

Tags
None

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:




All times are GMT -4. The time now is 04:53 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66