Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a text file with following contents:

NAME                       REGION        ADDRESS         STATUS
instance-name              europe-west1  1.2.3.4         IN_USE
instance-name-2            europe-west1  1.3.2.4         IN_USE
instance-name-3            europe-west1  1.5.3.2         IN_USE

I want to extract the IP address only from "instance-name-3". How would it be possible in that situation?

For example, this allows me to find all the IP addresses, but I only want the "instance-name-3" one:

grep -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0
-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" iplist.txt
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
176 views
Welcome To Ask or Share your Answers For Others

1 Answer

pBit more compact alternative to @waymobetta's solution

awk '/^instance-name-3  /{print $3}' your_file.txt

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...