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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-23-2008
samit_9999 samit_9999 is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 21
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
  #2 (permalink)  
Old 04-23-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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.
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 10:49 PM.


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