linux - bash + how to capture IP address from line -
i have many configuration files , line start line word have ip address
my target read line start line word file , print ip address
the problem ip address can in field in line can’t capture ip according field number
example
grep line file1.txt line /home/ariate/run.pl "voda sts 4 test - " "102841" && ssh 17.77.170.130 -p 2022 grep line file2.txt line /home/ariate/run.pl 137.77.170.30 "voda sts 4 test - " "102841" && ssh active please advice how capture ip address line ( solution can perl 1 liner )
expected results
echo $ip_from_line 17.77.170.130 echo $ip_from_line 137.77.170.30
using grep -oe:
grep -oe '\d+\.\d+\.\d+\.\d+' file 17.77.170.130 137.77.170.30 or else:
grep -op '\d+\.\d+\.\d+\.\d+' file linux bash perl awk
No comments:
Post a Comment