How to Swap 30 & 40 in IP address 192.30.40.1 using TCL
script?

Answers were Sorted based on User's Feedback



How to Swap 30 & 40 in IP address 192.30.40.1 using TCL script?..

Answer / gagik sukiasyan

set ip "192.30.40.1"
regsub {(\d+)\.(\d+)\.(\d+)\.(\d+)} $ip "\\1.\\3.\\2.\\4" new_ip
puts $new_ip

Is This Answer Correct ?    19 Yes 0 No

How to Swap 30 & 40 in IP address 192.30.40.1 using TCL script?..

Answer / indu sharma

There are three solutions.

set a 192.30.40.1
set b [ string range $a 3 4 ]
set c [ string range $a 6 7 ]
set d [ string replace $a 3 4 $c ]
set e [ string replace $d 6 7 $b]
puts $e

===OR=====
set a 192.30.40.1
set b [ split $a .]
set u [lindex $b 0]
set v [lindex $b 3]
set x [lindex $b 1]
set y [lindex $b 2]
set z [join "$u $y $x $v" .]
puts $z

====OR====
set ip 192.30.40.1
regexp {([0-9]+\.)([0-9]+\.)([0-9]+\.)([0-9]+)} $ip match 1st 2nd 3rd 4th
append new_ip $1st $3rd $2nd $4th
puts $new_ip

Is This Answer Correct ?    19 Yes 4 No

How to Swap 30 & 40 in IP address 192.30.40.1 using TCL script?..

Answer / hereiam

set x 192.30.40.1
set srcStr {([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)}
regexp $srcStr $x - d1 d2 d3 d4
regsub $srcStr $x "$d1.$d3.$d2.$d1" x

puts $x

Is This Answer Correct ?    14 Yes 3 No

How to Swap 30 & 40 in IP address 192.30.40.1 using TCL script?..

Answer / srinubalsu

set a 192.30.40.1
puts "Before swaping a: $a"
set a [split $a .]
set a [join "[lindex $a 0] [lindex $a 2] [lindex $a 1] [lindex $a 3]" .]
puts "After swaping a: $a"

Is This Answer Correct ?    8 Yes 0 No

How to Swap 30 & 40 in IP address 192.30.40.1 using TCL script?..

Answer / siddalingesha

set ip 192.30.40.1
set sp [split $ip "."]
set l [lindex $sp 1]
set m [lindex $sp 2]
set n [lreplace $sp 1 2 $m $l]
set sip [join $n "."]
puts "$sip"

Is This Answer Correct ?    8 Yes 0 No

How to Swap 30 & 40 in IP address 192.30.40.1 using TCL script?..

Answer / ram

set a 192.30.40.1
set a [split $a .]
set b [lreplace $a 1 2 "40" "30"]
puts [join $b .]

Is This Answer Correct ?    8 Yes 3 No

How to Swap 30 & 40 in IP address 192.30.40.1 using TCL script?..

Answer / mahesh

# 6 set ip "192.30.40.1"
regsub {(\d+)\.(\d+)\.(\d+)\.(\d+)} $ip "\\1.\\3.\\2.\\4"
new_ip
puts $new_ip

Is This Answer Correct ?    6 Yes 1 No

How to Swap 30 & 40 in IP address 192.30.40.1 using TCL script?..

Answer / ritu gupta

set ip 192.30.40.1
set updatedIp [ string map {30 40 40 30 } $ip ]

Is This Answer Correct ?    6 Yes 3 No

Post New Answer

More Tcl Interview Questions

WHAT IS TCL?

4 Answers   Airtel,


How to extract "information" from "ccccccccaaabbbbaaaabbinformationabcaaaaaabbbbbbbccbb" in tcl using a single command?

12 Answers   Wipro,


Where can find the sample tcl programs?

3 Answers  


How TCL works

1 Answers   Cisco,


{Anu Anudeep Anukumar Amar Amaravathi Aruna} is their any possibility to find the letter "a"in the given list? if yes how?

3 Answers   Cisco, HCL,






Set ip address as 10.30.20.1 write a script to replace the 30 with 40 ?

9 Answers  


if i give in numbers output should be in characters example : set a 23 o/p twentythree

1 Answers   Alcatel,


Write a proc to increment the ip by the given no. of times. The incremented IPs should be a valid one. Ex: proc <name> {ip no_of_incrments} { body }

2 Answers  


Test case on windows calculator?

1 Answers  


Write a program to increment IP address to +10 and verify it is correct ip or not ?? example my ip is 172.122.132.143 increment this ip to +10 and verify it is valid ip or not

1 Answers   Alcatel,


how to remote log in to a system A to system B ,execute commands in it and collect the log in system A from B using TCL script??  

1 Answers   Global Edge, Sandvine,


how to write the startup scripts in winrunner? can any body explain with example code?

0 Answers  


Categories