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
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 |
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 |
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 |
Answer / srinubalsu
set ip 10.30.20.1
puts [join [lreplace [split $ip .] 1 1 40] .]
| Is This Answer Correct ? | 1 Yes | 0 No |
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 |
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 |
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 |
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 |
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
How increment a character? For example, I give 'a' and I should get 'b'.
{Anu Anudeep Anukumar Amar Amaravathi Aruna} is their any possibility to find the letter "a"in the given list? if yes how?
Test case on windows calculator?
how to write the startup scripts in winrunner? can any body explain with example code?
Where can find the sample tcl programs?
how to increment eacl element in a list ? eg: incrlist {1 2 3} =>2 3 4
Hi all, Is there any certification exams available for TCL and Perl. If so please let me know, my mailid is vpbharathi@gmail.com. Thanks in advance, Bharathi.P
Which scripting language is better among TCL Perl and Python and why?
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
Problems with utf-8 between Mac and PC
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 }