Find and replace content in 100 lines

Alex Merritt merritt.alex at gmail.com
Fri May 1 22:18:34 UTC 2015


On Fri, May 1, 2015 at 5:26 PM, Mike Clarke <jmc-freebsd2 at milibyte.co.uk>
wrote:

> On Fri, 1 May 2015 16:20:07 -0400
> Alex Merritt <merritt.alex at gmail.com> wrote:
> >
> 's:"../../../arch1/arch14":"../../../../../../foo/foo2/foo3/arch1/arch14":g'
> > input.html
>
> Although that would almost certainly work OK in the OP's case  it would
> be safer to use:
>
>
> 's:"\.\./\.\./\.\./arch1/arch14":"../../../../../../foo/foo2/foo3/arch1/arch14":g'
>
>  otherwise if there was  something like "../../d1/arch1/arch14" it would
>  become "../../../../../../foo/foo2/foo3/arch1/arch14" which is probably
>  not what would be intended.
>

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

-Alex


More information about the freebsd-questions mailing list