LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-27-2008, 12:36 PM   #1
tekmann33
Member
 
Registered: Nov 2006
Posts: 188

Rep: Reputation: 30
compare two files


I am trying to determine what is the best way to perform this task.

I have two files: file_short and file_long

file_short has a list of entries that look like this:

4738219074|hfkdafdak
47381904730890|jfkdl;saj
8909890-8|jfkdas

file_long has the same types of entries, only more of them.

What I want to do is compare the two files, and the lines that are the same up to the pipe "|", I want to display those entries.

I've been looking at the "cmp" command, but I don't see how to compare only up to a deliminator.
 
Old 10-27-2008, 12:44 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
That's because they (diff won't either) don't.

You'll need to use a script of sorts.
Pre-process the content so it's being output up to your
delimiter, then feed the ones with matches into a grep
over the original files.



Cheers,
Tink
 
Old 10-28-2008, 08:09 AM   #3
DotHQ
Member
 
Registered: Mar 2006
Location: Ohio, USA
Distribution: Red Hat, Fedora, Knoppix,
Posts: 545

Rep: Reputation: 33
If it's a one time thing it might not be useful to try to code the solution.

If the short file is short enough, you could vi the long file and copy the short files portion of the line up to the pipe and plug it in the search criteria for vi (in vi command mode hit /then paste the string in and it will search for it. n will take you to the next occurrence of the string if there is one).

Or, strip both the short and long file of everything after the pipe and then use the diff command which will compare files. This would be the least preferential to me as diff output is a bit convoluted to read and can easily get confusing. JMHO.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
compare two files haydar68 Programming 8 08-16-2008 03:36 PM
Compare files in specific directory to files on CD szim90 Linux - Newbie 3 02-10-2007 08:39 PM
Compare two files namit Linux - Software 1 12-31-2005 08:10 AM
How do I compare 2 files? linuxhippy Slackware 6 03-26-2005 01:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration