Reputation: 45
I get daily a text file with ip:port, one per line, example:
11.22.33.44:80
22.33.44.55:8080
33.44.55.66:7777
I would like to parse the first ip and port in two different variables, then write them into another file, wait exceution of a program that use these variables, loop this cycle to pass all the ip:port to the file and execute program.
How can I do that?
thank you
Upvotes: 2
Views: 5134
Reputation: 532368
A pure bash solution:
while IFS=: read ip port; do
echo $ip $port
done < in.txt
This has the advantage of allowing you to set variables inside the while loop that remain available after the loop completes.
Upvotes: 5
Reputation:
cat in.txt | sed -e "s/:/ /" | while read ip port
do
echo $ip $port # or do something with it
done
Upvotes: 2