LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   compare two files (https://www.linuxquestions.org/questions/linux-newbie-8/compare-two-files-679363/)

tekmann33 10-27-2008 12:36 PM

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.

Tinkster 10-27-2008 12:44 PM

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

DotHQ 10-28-2008 08:09 AM

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.


All times are GMT -5. The time now is 05:47 AM.