The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 01: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 02: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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-18-2008
prashanth.spl prashanth.spl is offline
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
  #2 (permalink)  
Old 06-20-2008
guruparan18 guruparan18 is offline
Registered User
  
 

Join Date: May 2008
Location: India
Posts: 37
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.
  #3 (permalink)  
Old 06-20-2008
apsprabhu apsprabhu is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 43
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
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 09:27 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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