So i have a list of servers in one file called Servers.txt
And in another file called hostgroups.cfg, i want to remove each and every one of the servers in the Servers.txt file.
The problem is, the script I wrote is having a problem removing the exact servers in the Servers.txt file.
for EACH in `cat /var/home/me/Servers.txt`
do
cat /var/home/me/hostgroups.cfg | sed "s/$EACH//g" > /var/home/me/hostgroups.cfg1
cp /var/home/me/hostgroups.cfg1 /var/home/me/hostgroups.cfg2
cp /var/home/me/hostgroups.cfg1 /var/home/me/hostgroups.cfg
done
The hostgroups.cfg file often contains servernames with similar matching names and getting sed to remove JUST the server in the $EACH variable is another problem i keep encountering.
do you means your script will delete "are" and "hare" when you only want to delete "are"?
try the "\b" anchor,it match a whole word which is between two \b.
sed 's/\bABC\b//' will delete the ABC,not ABCD
There are several chunks similar to this in the hostgroups.cfg file.
define hostgroup {
alias PRODUCTION
hostgroup_name staged-hosts
members lht-rater-09.medy0.s.blah.net,db-tools-01.kedy0.s.blah.net,lhtgen-13.kedy0.s.blah.net,lhtgen-13.kedy0.s.blah.net,lhtgen-14.kedy0.s.blah.net,lhtgen-15.kedy0.s.blah.net,lhtgen-16.kedy0.s.blah.net,lhtgen-15.bedy0.s.blah.net,lhtgen-16.bedy0.s.blah.net,lhtgen-18.kedy0.s.blah.net,lhtgen-19.kedy0.s.blah.net,edge-evntpr-02.medy0.s.blah.net,edge-evntpr-04.medy0.s.blah.net,wifi-evntpr-01.vedy0.s,wifi-evntpr-02.vedy0.s,wifi-evntpr-03.vedy0.s,wifi-evntpr-04.vedy0.s,edge-evntpr-01.kedy0.s.blah.net,edge-evntpr-02.kedy0.s.blah.net,edge-tpr-03.kedy0.s.blah.net,edge-evntpr-04.kedy0.s.blah.net,edge-tpr-01.bedy0.s.blah.net,edge-evntpr-02.bedy0.s.blah.net,edge-tpr-03.bedy0.s.blah.net,edge-evntpr-04.bedy0.s.blah.net,edge-tpr-01.medy0.s.blah.net,edge-evntpr-03.medy0.s.blah.net
use test-hostgroup
}