i'm trying to use sed to replace the second occurrence of the 3 digit number in an I.P address and replace it with another value but it errors out. please advise
sed's substitute command's format: s/re/repl/flags
Note the absence of a trailing forward-slash delimiter. You want to use a flag value of 2 , not \2/ .
Although it probably has nothing to do with the error, the dot is not special in the replacement text. You can simply write x. instead of x\. . Pedantically speaking, \. in the replacement text is an undefined sequence. An implementation is allowed to treat it as it pleases; it can treat the backslash specially and quote the dot, or it can treat the backslash literally and replace the matching text with \. , or it can abort with a syntax error. Dropping the backslash in the replacement text is the simplest and most portable option.
thanks allister. as you pointed out i had 2 issues in there . one was with the extra \ after the replace pattern and the extra \ before the flag of 2nd occurrence. that fixed it .
also, the treatment of \ before the dot was not necessary in this case.