revise "([^/]+)$" into '([^/]+)$' in a lot of files under a directory.

Pieter van Oostrum pieter-l at vanoostrum.org
Sun Nov 17 14:28:55 EST 2019


Pieter van Oostrum <pieter-l at vanoostrum.org> writes:

> It isn't that difficult with sed, only you have to chose a different
> character than / in the substitute command, one that is not present in
> both texts, e.g instead of s/a/b/ use s=a=b=.
>
> And then the special characters " ' () [ and $ must be escaped for the
> shell, and [ and $ also for the regexp.
> Then it comes down to
> sed -e s=\"\(\\[^/]+\)\\$\"=\'\(\[^/]+\)\$\'= file

To be honest, I myself would use Emacs, with rgrep and wgrep to do this.
-- 
Pieter van Oostrum
WWW: http://pieter.vanoostrum.org/
PGP key: [8DAE142BE17999C4]


More information about the Python-list mailing list