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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
10-27-2008, 01:36 PM
|
#1
|
Member
Registered: Nov 2006
Posts: 188
Rep:
|
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.
|
|
|
10-27-2008, 01:44 PM
|
#2
|
Moderator
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
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
|
|
|
10-28-2008, 09:09 AM
|
#3
|
Member
Registered: Mar 2006
Location: Ohio, USA
Distribution: Red Hat, Fedora, Knoppix,
Posts: 548
Rep:
|
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 07:28 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|