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
compare the column from 3 files and merge that line ganesh_mak Shell Programming and Scripting 8 04-14-2008 04:56 AM
awk compare column between 2 files phamp008 Shell Programming and Scripting 3 01-17-2008 09:24 PM
compare two col from 2 files, and output uniq from file 1 pp56825 Shell Programming and Scripting 2 01-10-2008 08:10 AM
Compare Column value from Two Different Files hanie123 Shell Programming and Scripting 7 04-02-2007 06:34 AM
compare 2 files, output dups to file blt123 UNIX for Dummies Questions & Answers 2 07-15-2004 07:31 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 04-23-2008
Registered User
 

Join Date: Sep 2006
Posts: 20
Compare 2 files for a single column and output differences

Hi,

I have a column in 2 different files which i want to compare, and output the results to a different file. The columns are in different positions in those 2 files.
File 1 the column is in position 10-15
File 2 the column is in position 15-20

Please advise

Thanks
Reply With Quote
Forum Sponsor
  #2  
Old 04-23-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
With "the results", do you mean whether they were identical, or which lines differed, or which lines were identical, or both, or something else?

The comm command can compare sorted files. If your shell supports the <(...) construction, you don't even need temporary files:

Code:
comm <(cut -c10-15 file1 | sort) <(cut -c15-20 file2 | sort) >results
If you do need temporary files, it's a bit messy:

Code:
cut -c10-15 file1 | sort >/tmp/file1.tmp
cut -c15-20 file2 | sort >/tmp/file2.tmp
comm /tmp/file1.tmp /tmp/file2.tmp >results
resultcode=$?  # in case you want it
rm /tmp/file1.tmp /tmp/file2.tmp
See the comm manual page for what exactly the output means. You might want to omit e.g. the last column with the -3 option.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 08:13 PM.


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

Content Relevant URLs by vBSEO 3.2.0