I am using GNU SED for find and replace functionality on large files(upto 2GB).
Find and replace characters can contain any characters, hence I want find and replace parameters to be treated as plain text as it comes.
I do not want to treat either find or replace parameters as regex by sed command.
I have experimented a lot, but every time I am getting new combinations of regex which does not work for sed as plain text.
How can this be achieved?
Is there any formula to escape the special characters?
Note: I am using
~ operator as command seperator instead of
Below is the example
sed -ne "s~^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$~Replace" -ne "w output.txt" "input.txt"
Above command does not work, as it treats the find parameter as regex(as it is regex). Hence to find the text I have to escape some special characters in regex as below
sed -ne "s~\^\[-+\]?\[0-9\]\*\\.?\[0-9\]+(\[eE\]\[-+\]?\[0-9\]+)?\$~Replace" -ne "w output.txt" "input.txt"
In another example I have to modify
I do not want to mofify input.
So is there any universal rule for escape sequence?