-1

I want to replace the first string with the next

FindText[1]=/Folder 1/01. SubFolder/Demo(Object)

ReplaceText[1]=/Folder 1/01. SubFolder/02. SubFolder/Demo(Object)

I have tried this option with "|" but doesn't work.

>>sed -i 's|FindText[1]=/Folder 1/01. SubFolder/Demo(Object)|ReplaceText[1]=/Folder 1/01. SubFolder/02. SubFolder/Demo(Object)|g' filename.txt

The square brackets in the find expression doesn't seem to be found.

Le Pain
  • 75
  • 9
  • 1
    Square brackets are a regex special character and have to be escaped. I'm pretty sure there's a duplicate somewhere. – Benjamin W. May 28 '19 at 15:02
  • The duplicate is very general, but definitely covers your case. – Benjamin W. May 28 '19 at 15:03
  • Note that the duplicate covers a lot of territory. For the most part, `sed` uses POSIX BRE (Basic Regular Expression) syntax, though modern versions often have an option (`-E` and/or `-r`) to enable ERE (Extended Regular Expression) syntax. Additionally, you can match a newline with `\n`; in the GNU version but not all others, you can use `\n` in the replacement text as a newline. Some (many) versions of `sed` also feature extensions to the ERE syntax which get close to the BRE functionality, but with differences in notation (requiring backslashes before characters that an ERE would not need). – Jonathan Leffler May 28 '19 at 16:07

1 Answers1

0

try this:

sed -i 's|FindText\[1\]=/Folder 1/01. SubFolder/Demo(Object)|ReplaceText\[1\]=\/Folder 1\/01\. SubFolder\/02\. SubFolder\/Demo\(Object\)|g' filename.txt

special characters like \, [, ], (, ) and . must be escaped!

UtLox
  • 3,744
  • 2
  • 10
  • 13