0

Is it possible to use sed to replace the entire example bracketed line below? I seem to be running into trouble finding out a delimiter to use since / and many other special characters exist in the actual line I want to replace.

Line needing replacing:

This is a random example since the actual line I want to use is much less friendly to the eyes.

[...]
<example>=(a,b,c);{!@#$%^&*?/};</example>
[...]

If there is any tool better suited for this please let me know. Any help would be greatly appreciated.

1 Answers1

0

If you want to replace the entire line only, you can use a simple workaround in a similar fashion to this answer.

Here is your line:

<example>=(a,b,c);{!@#$%^&*?/};</example>

The workaround is, print this line before the rest of the file, then use Sed to change any lines which entirely consist of an exact match of the first line.

{ printf '%s\n' '<example>=(a,b,c);{!@#$%^&*?/};</example>'; cat somefile;} |
  sed -e '1h;1d;G;s/^\(.*\)\n\1$/text to change to/;t' -e 's/\n.*$//'

However—you should learn which characters need escaping in a Sed regex, anyway.

Wildcard
  • 36,499