Find and replace content in 100 lines

Mike Clarke jmc-freebsd2 at milibyte.co.uk
Sat May 2 09:23:42 UTC 2015


On Fri, 1 May 2015 18:18:12 -0400
Alex Merritt <merritt.alex at gmail.com> wrote:

> Hm, yes, the picket fence. How about
> 
> sed -i .orig -r
> 's:"((\.\./){3})arch1/arch14":"\1\1foo/foo2/foo3/arch1/arch14":g' input.html
> 
> Group it and repeat as \1

Yes, much neater, except that you will need sed -E otherwise you'd need
to escape all the grouping parentheses.

And to make it even more compact, how about

curlew:/tmp% cat input.html

aa"../../../arch1/arch14"bb
ccc"../../d1/arch1/arch14"ddd
ee"../../../arch1/arch14"ff

curlew:/tmp% sed -E 's:(([.]{2}/){3}):\1\1foo/foo2/foo3/:' input.html

aa"../../../../../../foo/foo2/foo3/arch1/arch14"bb
ccc"../../d1/arch1/arch14"ddd
ee"../../../../../../foo/foo2/foo3/arch1/arch14"ff

-- 
Mike Clarke


More information about the freebsd-questions mailing list