i'm trying grep file similar text:
1.1.1.1-text1 2.2.2.2-text2 3.3.3.3-text3
and put each grep result different variable this:
ip=$(cat nodes.txt | grep -o '^[^-]*') curl -k -sl -w 'response code: %{http_code} time: %{time_total}' $ip -o /dev/null # variable ip value of 1.1.1.1 curl -k -sl -w 'response code: %{http_code} time: %{time_total}' $ip -o /dev/null # variable ip value of 2.2.2.2 curl -k -sl -w 'response code: %{http_code} time: %{time_total}' $ip -o /dev/null # variable ip value of 3.3.3.3
so test results this:
test 1.1.1.1-text1 response code: 200 time: 0.000 test 2.2.2.2-text2 response code: 200 time: 0.000 test 3.3.3.3-text3 response code: 200 time: 0.000
try sth this:
#!/bin/bash while ifs='' read -r line || [[ -n "$line" ]]; ip=`echo $line | grep -o '^[^-]*'` echo $ip # can use $ip variable proper value file # ... done < nodes.txt
Comments
Post a Comment