Looking for a way using sed/awk/perl to replace port numbers in a file with an incrementing number. The original file looks like...
Host cmg-iqdrw3p4
LocalForward *:9043 localhost:9043
Host cmg-iqdro3p3a
LocalForward *:10000 localhost:10000
Host cmg-iqdro3p3b
LocalForward *:10000 localhost:10000
......
And I want to convert it to:
Host cmg-iqdrw3p4
LocalForward *:9043 localhost:2062
Host cmg-iqdro3p3a
LocalForward *:10000 localhost:2063
Host cmg-iqdro3p3b
LocalForward *:10000 localhost:2064
.......
I used sed to convert 'localhost:xxxx' to 'localhost:'. In vi, I used the following to add back the incrementing port number.
:let i=2000 | g/localhost:/s//\="localhost:".i/ | let i=i+1
Is there a way to do it all in sed? Sed, awk, perl or shell script answers would all be welcome too. Thanks.