sed second occurence error

Hi Guys,

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

$ cat infil
3538,,,,,,ID,ID1,,,,,,,,,,,123.110.24.5
sed 's/[0-9]\{1,3\}\./x\./\2/' infil
sed: -e expression #1, char 22: unknown option to `s'

same error when i use with -e switch . can some point me where i'm going wrong here

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.

Regards,
Alister

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.

Thanks mate.