From owner-freebsd-questions@FreeBSD.ORG Sat May 2 09:23:42 2015 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 14F001A2 for ; Sat, 2 May 2015 09:23:42 +0000 (UTC) Received: from avasout08.plus.net (avasout08.plus.net [212.159.14.20]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (Client CN "Bizanga Labs SMTP Client Certificate", Issuer "Bizanga Labs CA" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 9DA9713AE for ; Sat, 2 May 2015 09:23:40 +0000 (UTC) Received: from curlew.milibyte.co.uk ([80.229.31.82]) by avasout08 with smtp id NxLU1q0041mJoLY01xLVVt; Sat, 02 May 2015 10:20:29 +0100 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=GcuZnGnL c=1 sm=1 tr=0 a=cd0K7rcWwnZFf6xQxRobyA==:117 a=cd0K7rcWwnZFf6xQxRobyA==:17 a=D7rCoLxHAAAA:8 a=0Bzu9jTXAAAA:8 a=kj9zAlcOel0A:10 a=h1PgugrvaO0A:10 a=pGLkceISAAAA:8 a=yBtIYoe-v1W-EwV_EP4A:9 a=CjuIK1q_8ugA:10 Received: from curlew.lan ([192.168.1.13]) by curlew.milibyte.co.uk with esmtp (Exim 4.85) (envelope-from ) id 1YoTaz-000Knm-MS; Sat, 02 May 2015 10:20:28 +0100 Date: Sat, 2 May 2015 10:20:25 +0100 From: Mike Clarke To: Alex Merritt Cc: Nancy Belle , freebsd-questions Message-ID: <20150502102025.2e970d51@curlew.lan> In-Reply-To: References: <20150501222634.371373f0@curlew.lan> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.27; amd64-portbld-freebsd10.0) MIME-Version: 1.0 X-SA-Exim-Connect-IP: 192.168.1.13 X-SA-Exim-Mail-From: jmc-freebsd2@milibyte.co.uk Subject: Re: Find and replace content in 100 lines Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-SA-Exim-Version: 4.2 X-SA-Exim-Scanned: No (on curlew.milibyte.co.uk); Unknown failure X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 02 May 2015 09:23:42 -0000 On Fri, 1 May 2015 18:18:12 -0400 Alex Merritt 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