When do you use forward slashes in SED?

When do you use forward slashes in SED?

The trailing ‘g’ just says to replace all occurrences on a given line, not just the first. And of course you need to separate the ‘s’, the ‘g’, the old, and the new from each other. This is where you must use forward slashes as separators.

How to replace a backslash with a forward slash?

‘ s / \\ / / / g ‘ which will replace all backslashes with forward slashes. For me, this replaces one backslash with a forward slash. The first \\ is to insert an input, the second \\ will be the one you want to substitute.

How to replace two forward slashes in a comment?

If successful, replace that portion matched with replacement. The replacement may contain the special character & to refer to that portion of the pattern space which matched, and the special escapes \\1 through \\9 to refer to the corresponding matching sub-expressions in the regexp.

Can you use a different delimiter for the s command of SED?

You can use a different delimiter for the s command of sed so you do not have to escape slashes in the pattern (I used # as a delimiter). I think the problem is the field separator of the awk command. Change the order, first the sed commands, than the awk command:

Why does the command replace SED not work?

The problem is the / in the text you want to replace. This is a special character for sed and therefore you need to escape it with a \\. Also as pointed out in the comments: the command also fails because of the -e option which expects a script. Thanks for contributing an answer to Unix & Linux Stack Exchange!

How to replace old text with new text in SED?

This may be leaner and clearer that filtering through a command such as tr or sed. The sed command in this case is ‘s/OLD_TEXT/NEW_TEXT/g’. The leading ‘s’ just tells it to search for OLD_TEXT and replace it with NEW_TEXT.

When to use / as a separator in SED?

There’s no reason to use / as the separator in sed. But if you really wanted to: If your text is in a Bash variable, then Parameter Substitution $ {var//\\\\//} can replace substrings: This may be leaner and clearer that filtering through a command such as tr or sed.