Max Powers
Max Powers

Reputation: 1179

tcl string replace ip address 10.1.1.1 to 10.1.1.0

Hi all I have a variable which is an ip address of 10.1.1.1 I want to replace the last octet in the string to b 0

I have tried a few things from string replace and regsub but I have not really got anything that worked for me. can someone suggest how to change a string of 10.1.1.1 to 10.1.1.0 ?

I appreciate any help.

Upvotes: 1

Views: 620

Answers (2)

glenn jackman
glenn jackman

Reputation: 247082

% set ip 10.1.1.1
10.1.1.1
% set new [join [lreplace [split $ip .] end end 0] .]
10.1.1.0

Upvotes: 2

Lily Ballard
Lily Ballard

Reputation: 185801

What did you try? regsub can do this pretty trivially.

regsub {\d+$} $input 0

Upvotes: 1

Related Questions