SlackwareThis Forum is for the discussion of Slackware Linux.
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.
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.
Greets all. I'm having a brain freeze and can't figure out this simple problem. Been in windows too much I guess...
I have 2 files. File 1 is a complete list of what I need. File 2 has one or more lines missing but is more or less the same as file 1. I need to compare file 1 and 2 but only print the extra lines found in file 1. The files contain nothing but single words on each line if that matters. I've looked into sdiff, cmp, awk, uniq et. all but am still stuck for some reason. None of those seem to do what I want except for some sort of awk array maybe... But that still seems like overkill.
tail -n outputs the last N lines not omits the first line. That could short me a bunch of files...
piping to sed isn't bad I guess (kludgy tho) but that doesn't work in all circumstances. Here is my:
Code:
$ diff file1 file2
14c14
< mkcfm
---
>
The only thing your command does is scoot the 'name' I want to the beginning of the line. I'd have to pipe multiple times to get it solo... Extremely kludgy. Also, I'm assuming the "---" is because their is a blank line in file2 which I don't need to account for. This just doesn't seem the way to go. Way too specific and sloppy to boot.
I'd really like to get sort or uniq working. I guess I just don't understand uniq and why -u isn't doing anything.
Sure, I could write a perl script. I'd just tick everything in bash... I suck at perl. Besides, this is going into an existing bash script anyway.
The term 'kludgy' is subjective I guess. I'd really like to keep it down to just 2 or 3 short lines. This is an extremely easy operation (should be anyway), it's just eluding me for some reason.
Thanks for your help thus far. I'm still open to suggestions. Especially clarification on correct usage of uniq (ditching all repeated lines in one file)...
Yea.. I thought of that after posting my last comment. It works... But... Now we are back into being kludgy again... Don't you just love that word?
I don't get why this has to be a multiple step process but whatever I guess... See, once I extroplate the missing name, I have to fetch a version number to tag onto it, integrate it with the file that didn't have it and then sort them according to another 'order' file... I'm sorting twice, once with 'sort' and then thru a function I have to sort according to a static list.
That doesn't work. That gives the same exact output that is in file1 to begin with. All I need is the missing bits.
Code:
$ cat file1 file2 | sort -u
bird
boy
cat
dog
$cat file1
cat
boy
dog
bird
I don't NEED to sort anything. The only reason why I'm using 'sort' is because it seems to be necessary for comm to function. What I need is the missing words from file1...
And there it is... The elegant one-liner that has been eluding me...
Funny thing is, I tried that after your first post but gave sort the u switch instead of calling it vanilla. Seems my ignorance with these commands and patience with 'man' was the only problem here...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.