1

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 execution 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?

7ochem
  • 280
  • 1
  • 3
  • 12
MuZo
  • 13
  • 1
  • 3

1 Answers1

0
#!/bin/sh

while read line junk
do 
  addr=${line%%:*}
  port=${line##*:}
  ./nuke $addr $port
  retval=$?
  case retval in
    0) echo "$addr $port nuked" >> nuke.log ;;
    *) echo "$addr $port avoid nuke" >> nuke.log ;;
  esac

done < /some/file/with/ipports
Kondybas
  • 6,964
  • 2
  • 20
  • 24
  • Solved: http://stackoverflow.com/questions/11428579/shell-script-to-parse-ipport-from-a-text-file , going anyway to check your solution to learn – MuZo Jul 11 '12 at 08:56
  • rewrite solution to meet all your conditions :) – Kondybas Jul 11 '12 at 09:06