Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

Answers were Sorted based on User's Feedback



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

Answer / s.gun

% set ip 10.30.20.1
10.30.20.1
% regsub -all {30} $ip {40} ip
1
% puts $ip
10.40.20.1
%

Is This Answer Correct ?    7 Yes 3 No

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

Answer / indu sharma

In above answer if you have IP like 10.30.30.1 then it replace for all 30 with 40.But here i guess intention is just to replace one octet with 40.So following solves that issue:


set a 10.30.2.1
set b [ string replace $a 3 4 40 ]
puts $b

Is This Answer Correct ?    4 Yes 1 No

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

Answer / satyanarayana

here you can do this in multiple ways

1.regsub 30 $data 40 a
puts $a

this will give you the replaced string

2.string replace $data 3 4 40

this also will give you the replaced value

Is This Answer Correct ?    3 Yes 2 No

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

Answer / srinubalsu

set ip 10.30.20.1
puts [join [lreplace [split $ip .] 1 1 40] .]

Is This Answer Correct ?    1 Yes 0 No

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

Answer / anil

set a "10.30.20.1"
regsub "30" $a "40" a

Is This Answer Correct ?    1 Yes 0 No

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

Answer / siddalingesha

set i "10.30.20.1"
set n [split $i "."]
set k [lreplace $n 1 1 40]
set s [join $k "."]
puts "$s"

Is This Answer Correct ?    1 Yes 1 No

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

Answer / guest

set ip "10.30.20.1"
regsub -all {m\30\M} $ip 40 ip_new
puts $ip_new

Is This Answer Correct ?    0 Yes 0 No

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

Answer / amarnath

set ip 10.20.30.40
set a [split $ip .]
puts $a
set oct1 [lindex $a 0]
set oct2 [lindex $a 1]
set oct3 [lindex $a 2]
set oct4 [lindex $a 3]
#set oct3 50
set ip [join "$oct1 $oct2 $oct4 $oct3" "."]
puts $ip

Is This Answer Correct ?    0 Yes 0 No

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

Answer / sat

Set ip 10.30.20.1
split ip using split .
from the resultant list, use lreplace command to replace
element 30 with 20.

Is This Answer Correct ?    3 Yes 4 No

Post New Answer

More Tcl Interview Questions

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

12 Answers   Wipro,


How to run a package in tcl

2 Answers  


How to get the next ip for given ip ex: 10.10.10.1 -> 10.10.10.2 ex: 10.10.10.255 -> 10.10.11.0

5 Answers   Cisco, HCL,


 write a regular expressions to fetch all the valid ip's

3 Answers   Alcatel,


How do you find the length of a string without using string length command in TCL??

6 Answers   Hexaware,


1.What are the different ways to initialize a variable. How to differentiate global and local variables, explain it through a simple tcl program. 2.Create a list of week days and print the first and last character of each day using foreach command 3.Can you write a small program to verify the given input is file or directory.Before checking, just ensure that the file/dir exists or not in the given path. If the given input is a file, findout the size and verify that the file has all read ,write and execute permission.

3 Answers   ATTO, HCL,


Which scripting language is better among TCL Perl and Python and why? 

1 Answers   GE,


Problems with utf-8 between Mac and PC

1 Answers  


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

9 Answers  


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 TCL works

1 Answers   Cisco,


Test case on windows calculator?

2 Answers  


Categories