Reputation: 1140
I need to write multiple sed
script files. I can't seem to find a way to enable extended regex from within the script. Is this possible? It isn't possible for me to use option flags because the scripts need to run on an external environment which isn't under my control.
Upvotes: 2
Views: 1010
Reputation: 11862
You can try specifying the flag in the script shebang, say:
#!/bin/sed -rf
# script goes here
And then tell the admin to run the script as is (chmod a+x
it first, then ./script.sed
) so the shebang line is used for finding the right interpreter.
You may need to substitute /bin/sed
with the right path for your environment. Unfortunately you probably won't be able to use /usr/bin/env sed -r
for this (the extra -r
is a problem).
Upvotes: 4
Reputation: 183361
I think the answer to your question is "no", but, if this is GNU sed
, then you probably don't really need extended regular expressions, because GNU sed
's implementation of basic regular expressions actually supports the features of EREs that true POSIX BREs don't. Admittedly, the result is incredibly, painfully backslash-heavy — ERE's s/(a|b+|cd?)/e/g
becomes BRE's s/\(a\|b\+\|cd\?\)/e/g
— but it works.
Upvotes: 1