The embedded sed script is in a
'string'. After a ' the following ' ends it.
Code:
sed 's/ '\|' / \|\| /3' sample.txt
The shell passes it dequoted to sed:
This is different from your pure sed code
The | character is not special in a BRE (grep, sed) but it is in an ERE (grep -E, sed -r). And it should never be escaped in the replacement string.
Code:
sed 's/ | / || /3' sample.txt
Code:
sed -r 's/ \| / || /3' sample.txt
Code:
#!/bin/sed -f
s/ | / || /3
Code:
#!/bin/sed -rf
s/ \| / || /3