I have a file like thisKN1234.1KN2345.1KN1233.1I want to replace the . with v so that I can get output asKN1234v1KN2345v1KN1233v1After the . it is always 1 but after KN I can also have upto 5 digits. Something like this is also possible KN14345.1 and it's output should be KN14345v1I tried sed commandsed 's/KN\d+.1/KN\d+v1/g' file.txtbut nothing happened.How can i fix this?Perl solution would also be appreciated.Thanks
replacing a dot with a character using sed or perl
sed;perl
This:sed 's/KN\d+.1/KN\d+v1/g' file.txtdoesn't do anything because your sed is not likely to support \d (I think it's from Perl), so the pattern doesn't match anything. You may want to refer to this: Why does my regular expression work in X but not in Y?It wouldn't work as you want regardless, since the \d just escapes the d in the replacement part, and + isn't special, so your numbers get replaced.In Perl, you might want something like this:perl -pe 's/(KN\d+)\.1/$1v1/'  file.txt Where $1 expands to the first group in parenthesis, and the dot is escaped, since it's regex for any character. Orperl -pe 's/KN\d+\K\.1/v1/'  file.txt Where \K kills the preceding part of the match, so that it isn't replaced.Though if you don't care about the context of the dot, use tr. (or tr/// in Perl).