Re: sed – using variables containing "/"
- From: PleegWat <pleegwat@xxxxxxxxxx>
- Date: Sun, 12 Feb 2012 23:50:53 +0100
-----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-----
--
ubuntu-users mailing list
ubuntu-users@xxxxxxxxxxxxxxxx
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
- Follow-Ups:
- Re: sed – using variables containing "/"
- From: Johnny Rosenberg
- Re: sed – using variables containing "/"
- References:
- sed – using variables containing "/"
- From: Johnny Rosenberg
- sed – using variables containing "/"
- Prev by Date: RE: Jockey says that my Nvidia driver supports desktop effects but changes to compiz don't take effect
- Next by Date: Re: Athlon II x4 620
- Previous by thread: Re: sed – using variables containing "/"
- Next by thread: Re: sed – using variables containing "/"
- Index(es):
Relevant Pages
|