say have want match string foo.. regex foo\., escape special meaning of . character.
now in sed command, use . delimiter.
for search like, say, cat, works fine.
echo cat | sed 's.cat.dog.g' but when have literal . in search string, run problem. think, since . delimiter, regex foo\. should become foo\\\.. ideally, first pass of unescaping done sed make foo\., , passed along regular expression engine.
but instead, matches cat\\\.
echo 'cat.' | sed 's.cat\\\..dog.g' # cat. echo 'cat\.' | sed 's.cat\\\..dog.g' # dog is there way make work literal . when . used delimiter?
i'm asking question because want able have function
function escapeforextendedsed ($str, $delimiter = "/") { ... } which can escape correctly depending on caller using delimiter.
this works me:
echo 'cat.' | sed 's.cat[\.].dog.g' # cat.
Comments
Post a Comment