I have an issue with sed
that I have been able to recreate with the following simple example.
Consider the following input file (input.txt):
C:\A\quick\brown\fox\ jumps over the lazy dog
C:\A\quick\brown\fox\ ran with the hounds
I want to generate the following output
C:\Animal\ jumps over the lazy dog
C:\Animal\ ran with the hounds
I tried to create a simple shell script, using sed, but it is not performing the required substitution. Here is my script:
FROM_PATTERN="C:\A\quick\brown\fox\"
TO_PATTERN="C:\Animal\"
#FROM_PATTERN="C:\A\quick\brown\fox\" # Escaping backslash does not help either
#TO_PATTERN="C:\Animal\" # Escaping backslash does not help either
sed 's/$FROM_PATTERN/$TO_PATTERN/g' input.txt
#sed 's/"$FROM_PATTERN"/"$TO_PATTERN"/g' input.txt # Quoting the pattern does not help either
I am running bash
version GNU bash, version 4.4.12(3)-release-(x86_64-unknown-cygwin)
sed
call. – AdminBee Nov 09 '20 at 09:10