Solved

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

Posted on 2012-04-06
5
407 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
ID: 37817183
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
ID: 37817343
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
ID: 37817373
Or like this:

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

Assisted Solution

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

Accepted Solution

by:
woolmilkporc earned 200 total points
ID: 37817447
Or like this:

sort development_servers all_servers |uniq -u > non_development_servers
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
This code tracks birthdays 3 60
nagios alerts 3 33
Is doing tutor.com teaching in my situation advisable? 2 54
Coding C# in Linux 8 24
A short article about problems I had with the new location API and permissions in Marshmallow
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

910 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

23 Experts available now in Live!

Get 1:1 Help Now