sed – using variables containing "/"
PleegWat
pleegwat at telfort.nl
Sun Feb 12 22:50:53 UTC 2012
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 02/12/2012 07:53 PM, Johnny Rosenberg wrote:
> So, if the variable MyVar contains a ”/”, sed will fail and a
> workaround is to use another character instead of the ”/”
> character for sed, like in this case, ”@”. Is this the only
> workaround in this case or is there a more elegant one? The
> variable ”MyVar” must not be changed in any way, other than that,
> everything is allowed, I suppose…
I'm not aware of an elegant solution in sed. You can do this in awk
however:
awk -v MyVar="${MyVar}" '{ gsub( /\$1/, MyVar ); print }' -
Basically -v allows you to pass a shell variable into an awk variable,
which removes escaping concerns.
PleegWat
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iQEcBAEBAgAGBQJPOEJHAAoJEAM6sLJjDJaMSgEH/A0NmgTsRdCliEuKyxb7iD/y
0lsHnVcujzJ0OlVaVkpBrRtlv5rbFWKQynVXn4Y8I1c9UF8FdeDY9AfEWDUo0QYd
aLCPg9iUxDjo7UN52+nPRK8DCzsllxftK4efSA07AUhh/w8w0h03j19/vYOV5I0/
wPTWpp/WIpnXQw15xHFLJAmK7vqhbEk9lwC+dM33mzGVxLkAEtGlnPqPqttCkaen
dvvU7B2XFlY8Xd3wh2+2wficEethL04Q4tJTLMz6XcHM4fsdwpFV+D7wooJ4/jjh
bl9DiBAH35AdQzWaMrJ0NTo5G1q0rsaRHHWFjo8SPFfB64SQ8I4Mx0LuQjyC1xo=
=bWLb
-----END PGP SIGNATURE-----
More information about the ubuntu-users
mailing list