Awk Help - duplicates in $1 that match x & y in $2
I'm primarily a "Windows" systems administrator whose been getting his toes in the Linux waters. I am new to programming and advanced scripting so please bear with me and my incomplete example below.
I have exported all entries from our DNS zones. I used sed to remove everything other than the fqdn from the files. We have a few hundred hosts across a few dozen zones. Some hosts are not in all zones though.
I would like to use something like awk to determine which hosts are (or are not) in the domains I specify. Bonus might also be to accept input from a file (with the various domain names) but the simpler the better.
and so on. And again, some hosts are not in all zones.
I would like to do something like:
to figure out which hosts are (or maybe, are not) in the zones specified.
Obviously this script is incomplete. I can't figure out how to find duplicates from $1 and then search $2 for domain2 and domain3.
I want all duplicate (or triplicate or so on) hosts from $1 that match a few possible domain inputs from $2 to return, and nothing else. Since I may have the same host returned per domain a few times, if the result could be truncated to just the host once, even better.
I am not necessarily looking to be spoon fed a few completed examples though I wouldn't object. If you have a few ideas for me, I'd appreciate being pointed closer in the right direction.
Genius!
The second one did exactly what I was looking for as it sorted and summarized more cleanly. This was a lot simpler looking than I imagined. I appreciate your help and I will be able to modify this for use in other ways so I appreciate it very much!
---------- Post updated at 11:51 AM ---------- Previous update was at 11:25 AM ----------
Oh, one thing I also need to be able to do is use && for $2, not just |. So I would like to be able to filter by host1.temp.local host1.temp2.org etc etc.
That way if I get the request, which servers are in these four domains, I can use the &&, specify the domains, and get a list of the servers.
With the | I may get servers in some but not all of the specified domains. Thanks so far!
Oh, one thing I also need to be able to do is use && for $2, not just |. So I would like to be able to filter by host1.temp.local host1.temp2.org etc etc.
That way if I get the request, which servers are in these four domains, I can use the &&, specify the domains, and get a list of the servers.
With the | I may get servers in some but not all of the specified domains. Thanks so far!
I didn't understand what your second requirement was.
btw, you can use awk ... | sort -u instead of awk ... | sort | uniq
In the awk below I am trying to output those lines that Match between file1 and file2, those Missing in file1, and those missing in file2. Using each $1,$2,$4,$5 value as a key to match on, that is if those 4 fields are found in both files the match, but if those 4 fields are not found then missing... (0 Replies)
with below given format,
I have been trying to find out all IDs for those entries with duplicate names in 2nd and 3rd columns and their count like how many time duplication happened for any name if any,
0.237788 Aaban Aahva
0.291066 Aabheer Aahlaad
0.845814 Aabid Aahan
0.152208 Aadam... (6 Replies)
I am trying to create a cronjob that will run on startup that will look at a list.txt file to see if there is a later version of a database using database.txt as the source. The matching lines are written to output.
$1 in database.txt will be in list.txt as a partial match. $2 of database.txt... (2 Replies)
I am trying to look for $2 of file1 (skipping the header) in $2 of file2 (skipping the header) and if they match and the value in $10 is > 30 and $11 is > 49, then print the line from file1 to a output file. If no match is foung the line is not printed. Both the input and output are tab-delimited.... (3 Replies)
Hello,
I have a file contains two columns. I need to print the lines after “xxx” so i'm trying to match "xxx" & cut the lines after that. I'm trying with the grep & cut command, if there any simple way to extract this please help me.
Sample file :
name id
AAA 123
AAB 124
AAC 125... (4 Replies)
Hi,
i have a huge file that need to check for a pattern that occur more than once in a line like below:-
#lkk>cd-m>A0DV0>192.134.1.1 blablabladsdjsk
jshdfskfslfs
#lqk>cd-m>A1SV0>192.14.11.1 blalalbnalablab
balablablajakjakjakja
#pldqw>sf-w>PH67FR>168.55.1.1 balablabala... (5 Replies)
I need to take 2 input files and create 1 output based on matches from each file. I am looking to match field #1 in both files (Userid) and create an output file that will be a combination of fields from
both file1 and file2 if there are any differences in the fields 2,3,4,5,or 6.
Below is an... (5 Replies)
sed -e '1d' -e 's/^\(]\{2\}\)-\(]\{3\}\)-\(]\{4\}\).*/"0000020\1\200\3"\,/g' abc.txt
This script returns many duplicates due to the duplciates in the .txt file.
i.e.
...
"000002012149000060",
"000002012149000064",
"000002012149000064",
"000002012149000064",
"000002012149000064",... (9 Replies)
Hello, can someone help me how to find a word and 2 lines after it and then send the output to another file.
For example, here is myfile1.txt. I want to search for "Error" and 2 lines below it and send it to myfile2.txt
I tried with grep -A but it's not supported on my system.
I tried with awk,... (4 Replies)
I have a csv file in which i have to search a particular string and replace the data in any column with something else. How do i do it using awk.
file
------
2001,John,USA,MN,20101001,29091.50,M,Active,Y
2002,Mike,USA,NY,20090130,342.00,M,Pending,N... (3 Replies)