I have a ports.txt file containing the following data "IP Address, local port, remote port and protocol". This is what the file looks like:
1.1.1.1-22-2222-tcp
2.2.2.2-3000-4321-udp
3.3.3.3-80-8080-tcp
4.4.4.4-443-4443-tcp
What I would like to do is use SED to edit each line by putting the values from the ports.txt file in the correct places.
I've used line 1 from the ports.txt file as an example of the expected outcome:
-A PREROUTING -i eth0 -p tcp -m tcp --dport 2222 -j DNAT --to-destination 1.1.1.1:22
I have worked out that I can read line by line using a loop like this:
while read line; do echo $line; done < ports.txt
but I have no idea how to get SED to extract the values and put them into the required format.