ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
Dear all
I want to compare the zones in both my Linux Bind servers, So I greped the first line of all of them with
#> grep 'zone "' named.conf > named.1
and the same for named.conf 2
now I get two files named.1 named.2, with the following syntax
zone "domain1.com" in {
zone "domain2.com" in {
zone "domain3.cc" in {
zone "domain4.net" in {
zone "domain5.tv" in {
etc..
First Can any one tell me a grep command to just get the domains name between the "" in a file
second I want to compare between the both files and get the domains that in named.1 and not found in named.2
Thanx so much
the first command worked perfectly
But there's something in the second one
It compared with two files as they are arranged like each others, But they don't
For example name1
zone "domain1.com" in {
zone "domain2.com" in {
zone "domain3.cc" in {
zone "domain4.net" in {
zone "domain5.tv" in {
etc..
But named2
zone "domain5.tv" in {
zone "domain3.cc" in {
zone "domain2.com" in {
zone "domain4.net" in {
zone "domain1.com" in {
etc..
I just want it to get the domains that are in one of them and not in the other, To add it to the other one, Got it.
I just want it to get the domains that are in one of them and not in the other, To add it to the other one, Got it.
how about:
Code:
$ cat name1 name2 |sort |uniq > allnames
$ cat allnames
zone "domain1.com" in {
zone "domain2.com" in {
zone "domain3.cc" in {
zone "domain4.net" in {
zone "domain5.tv" in {
Of course, if the original order is important to you this might not be so great...
I recently had to prepare scripts that extracted the names of mpeg files in several video devices against one of the devices. I used the "comm" command to find entries in one list that were unique, and then used that list as a grep pattern file to the original.
Code:
$ cat rdytospot
#!/bin/bash
for file in *.RDY; do
sed -e '0,/Unmanaged/d' -e '/NETTEST/d' -e '/^$/,$d' -e '/^$/d' -e 's/\(.*MPG\).*/\1/' -e 's/[[:blank:]]//g' "$file"
done > unmanagedspots
sort -u unmanagedspots >unmsorted
comm -23 unmsorted solicitorlist >deletelist
if grep -f deletelist solicitorlist; then
echo Error! The delete list contains files in the solicitor
exit 1
fi
sed 's/^/del /' deletelist >clean.dvc
rm unmanagedspots unmsorted deletelist
You could do something similar:
Code:
sed -n '/^zone/s/^[^"]*"\([^"]*\)".*/\1/p' named2 | sort >named2list
sed -n '/^zone/s/^[^"]*"\([^"]*\)".*/\1/p' named1 | sort >named1list
comm -13 named1list named2list >UniqInNamed2
grep -f UniqInNamed2 named2
By the way, your two samples have exactly the same domain names, just in a different order.
Using different samples:
$ cat named1
zone "domain1.com" in {
zone "domain2.com" in {
zone "domain3.cc" in {
zone "domain4.net" in {
zone "domain5.tv" in {
$ cat named2
zone "domain8.tv" in {
zone "domain3.cc" in {
zone "domain7.com" in {
zone "domain4.net" in {
zone "domain1.com" in {
$ grep -f UniqInNamed2 named2
zone "domain8.tv" in {
zone "domain7.com" in {
No I don't want to arrange them, I just want to compare.
Thanx for help
Sorry mate, w/o sorting the diff output will be
garbage. With the sorting you get two sets that
(most likely) won't appear in either, and then
you could feed them back. If that's not what
you're after *I* can't help you.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.