-1

I have a variable that contains list of ips and i will like to remove the ip of the instance where the variable is set

Please see below

[root@ip-10-10-2-100 ~]# INSTANCE_IP=$(curl -s http://169.254.169.254/latest/meta-data/local-ipv4)

[root@ip-10-10-2-100 ~]# echo $INSTANCE_IP
10.10.2.100

[root@ip-10-10-2-100 ~]# IP_LIST=$(aws ec2 describe-instances --region us-east-1 --filters 'Name=tag:Name,Values=tw-app-ecs' 'Name=instance-state-name,Values=running' --query "Reservations[*].Instances[*].PrivateIpAddress" --output=text)

[root@ip-10-10-2-100 ~]# echo $IP_LIST
10.10.2.100 10.10.4.158

So what do i so to this variable IP_LIST so that i can remove the local ip (10.10.2.100) and have this expected outcome below?

EXPECTED OUTCOME:

[root@ip-10-10-2-100 ~]# echo $IP_LIST
10.10.4.158

This should be dynamic depending on which instance the variable is set. Will truly appreciate your help. Thanks!

uberrebu
  • 493
  • 5
  • 15
  • 32

1 Answers1

1

Just thought of grep -v After spending hours finding a way, finally found grep -v just minutes after posting

IP_LIST=$(aws ec2 describe-instances --region us-east-1 --filters 'Name=tag:Name,Values=tw-app-ecs' 'Name=instance-state-name,Values=running' --query "Reservations[*].Instances[*].PrivateIpAddress" --output=text | grep -v `curl -s http://169.254.169.254/latest/meta-data/local-ipv4`)
uberrebu
  • 493
  • 5
  • 15
  • 32