Solved

Need to weed out a list of servers from a list of servers with unix commands

Posted on 2012-04-06
5
406 Views
Last Modified: 2012-04-09
I have a list of about 400 development servers and a list of about 1500 servers which include those servers and the rest of out unix environment. What is a good way to remove the servers in the first list from the second and create a new file with only those servers? The lists are line separated - eg:

server1
server2
server3
0
Comment
Question by:Thaidog
  • 3
  • 2
5 Comments
 
LVL 37

Assisted Solution

by:Gerwin Jansen
Gerwin Jansen earned 300 total points
Comment Utility
There is an AWK trick to do this, put the servers you want to filter in filter.txt and the 1500 servers in servers.txt
awk 'NR==FNR{arr[$0];next}!($0 in arr)' filter.txt servers.txt >newfile.txt 

Open in new window

Sample:

$ cat filter.txt
server2
server3
$ cat servers.txt
server1
server2
server3
server4
server6
$ cat new_file.txt
server1
server4
server6
0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 200 total points
Comment Utility
sort development_servers > development_servers.sorted
sort all_servers > all_servers.sorted
comm -1 -3 development_servers.sorted all_servers.sorted  > non_development_servers
rm development_servers.sorted all_servers.sorted
0
 
LVL 37

Assisted Solution

by:Gerwin Jansen
Gerwin Jansen earned 300 total points
Comment Utility
Or like this:

grep -v -f filter.txt servers.txt
0
 
LVL 37

Assisted Solution

by:Gerwin Jansen
Gerwin Jansen earned 300 total points
Comment Utility
grep -v -f filter.txt servers.txt > new_file.txt
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 200 total points
Comment Utility
Or like this:

sort development_servers all_servers |uniq -u > non_development_servers
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Solaris 10.  Nmap installation fails 2 38
Oracle Finace 3 42
control image tags in a string ? 12 58
Sendmail STARTTLS error 37 38
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
A short article about problems I had with the new location API and permissions in Marshmallow
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now