Reputation: 45
I wrote a script to replace certain expressions and remove others, but it failed in cleaning up special characters. Setting LANG=C solved that, but is it possible to set that environment variable from within sed?
Upvotes: 2
Views: 943
Reputation: 28676
If your script is a sed
script, you can just bump that part down and put it into a standard shell script. e.g.
#!/usr/bin/sed -f
1 {
x
s/^$/ /
s/^.*$/&&&&&&&&/
x
}
into
#!/bin/sh
export LANG=C
/usr/bin/sed '
1 {
x
s/^$/ /
s/^.*$/&&&&&&&&/
x
}
' "$@"
(from an example in the sed
info
document.)
With the trailing "$@"
, it should pass arguments and handle stdin the same way.
Upvotes: 0
Reputation: 359875
You can set the environment variable so that it's active only for the single invocation of a command or script:
LANG=C sed ...
or
LANG=C sedscript
Upvotes: 1
Reputation: 16035
No, but you don't have to. You can set the envirinment variable before executing your sed command.
Upvotes: 2