Solved

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

Posted on 2012-04-06
5
411 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 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Suggested Solutions

A short article about a problem I had getting the GPS LocationListener working.
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?
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

829 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