Solved

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

Posted on 2012-04-06
5
415 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 38

Assisted Solution

by:Gerwin Jansen, EE MVE
Gerwin Jansen, EE MVE 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 38

Assisted Solution

by:Gerwin Jansen, EE MVE
Gerwin Jansen, EE MVE earned 300 total points
ID: 37817373
Or like this:

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

Assisted Solution

by:Gerwin Jansen, EE MVE
Gerwin Jansen, EE MVE 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 Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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 …
Introduction to Processes

729 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