From owner-freebsd-questions@FreeBSD.ORG Fri May 1 01:14:14 2015 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id E46CDBAE for ; Fri, 1 May 2015 01:14:13 +0000 (UTC) Received: from mail-qk0-x232.google.com (mail-qk0-x232.google.com [IPv6:2607:f8b0:400d:c09::232]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 9D0361736 for ; Fri, 1 May 2015 01:14:13 +0000 (UTC) Received: by qkhg7 with SMTP id g7so44320456qkh.2 for ; Thu, 30 Apr 2015 18:14:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=MZAcAGbIVl5AgDRhP+r9k6qHoj7DEo5yFog2xpHhqCI=; b=tzyfDtgR/0HhYXYmcHQIXcaFoHYSykYLZUCUJEFpY6XbACtJVxSzxi0c6fbKCpYCMq w1ZiTUo8oBysGqCBJ2ypiwkqq0CIOdEYdZ4rDwVKDqjdHATnUESHeJNN3iudyQhVoDXO q53P/0/FCaZZ23aauF+iZmc63AqmstnjDwxQwl+laFmanm4eauJrbDOz8x2soVz4hQyA YxUo68Gou0rh1KrFxlz4AUJzMofkWl/hDpYvF4GhClAUxw08EFhm1iL5DKCCAG3W4sq0 ZIm9o4nJQw6u14v4dmF+N5drUXjWsvhDL3eZP7VjzPyI8Sojz93zvMCmidajCn2PqtR8 5m4A== X-Received: by 10.55.50.201 with SMTP id y192mr13846481qky.10.1430442852614; Thu, 30 Apr 2015 18:14:12 -0700 (PDT) Received: from smaug.zep.net (pool-72-66-73-67.washdc.fios.verizon.net. [72.66.73.67]) by mx.google.com with ESMTPSA id a6sm2260660qgf.17.2015.04.30.18.14.11 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Apr 2015 18:14:11 -0700 (PDT) Message-ID: <5542D362.4060802@gmail.com> Date: Thu, 30 Apr 2015 21:14:10 -0400 From: zep User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: freebsd-questions@freebsd.org Subject: Re: Find and replace content in 100 lines References: In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable 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: Fri, 01 May 2015 01:14:14 -0000 On 04/30/2015 08:58 PM, Nancy Belle wrote: > Hi freebsd-questions > > I hope y'all don't mind another question, although I have a slim idea h= ow to do it, but it would need some trial and error to get there. Probabl= y use either sed or perl in some fashion. It's the fashion I'm unsure of.= > > Running fbsd-9.3 > > This is probably easy for the script gurus on the list. > > Here's the need to fix about 100 lines in a single *.html file: > find this "../../../arch1/arch14" > replace with "../../../../../../foo/foo2/foo3/arch1/arch14" > > The quotes are there too. > > Hope for help, please! > normally I'd send jut to the poster, but in the offhand chance this can help someone else, here are my results: [zep@nemesis x]$ cat junk this stuff is easy Here's the need to fix about 100 lines in a single *.html file: find this "../../../arch1/arch14" replace with "../../../../../../foo/foo2/foo3/arch1/arch14" find this "../../../arch1/arch14" find this "../../../arch1/arch14" find this "../../../arch1/arch14" find this "../../../arch1/arch14" find this "../../../arch1/arch14" find this "../../../arch1/arch14" find this "../../../arch1/arch14" [zep@nemesis x]$ cat try perl -p -i -e 's?"../../../arch1/arch14"?"../../../../../../foo/foo2/foo3/arch1/arch14"= ?g' [zep@nemesis x]$ perl -p -i -e 's?"../../../arch1/arch14"?"../../../../../../foo/foo2/foo3/arch1/arch14"= ?g' junk [zep@nemesis x]$ cat junk this stuff is easy Here's the need to fix about 100 lines in a single *.html file: find this "../../../../../../foo/foo2/foo3/arch1/arch14" replace with "../../../../../../foo/foo2/foo3/arch1/arch14" find this "../../../../../../foo/foo2/foo3/arch1/arch14" find this "../../../../../../foo/foo2/foo3/arch1/arch14" find this "../../../../../../foo/foo2/foo3/arch1/arch14" find this "../../../../../../foo/foo2/foo3/arch1/arch14" find this "../../../../../../foo/foo2/foo3/arch1/arch14" find this "../../../../../../foo/foo2/foo3/arch1/arch14" find this "../../../../../../foo/foo2/foo3/arch1/arch14" [zep@nemesis x]$ the "junk" file was just some text to try things with. to make it fully functional I'd end with something like: cd $WEB_DIR find . -type f (or maybe -name "*.html" if you're sure all files will be =2Ehtml) | xargs \ perl -p -i -e 's?"../../../arch1/arch14"?"../../../../../../foo/foo2/foo3/arch1/arch14"= ?g' but I'd make sure to do lots of backups and try first on some junk files/things you don't really need/are a much smaller subset of files on a non prod machine. I just think it'll work, I can't be sure. oh wait. you said a single file. so that could work on just the on file instead of a find. (sorry, too lazy to erase all that, I guess) or you could use vi on the file and do something like : 1,$ s?"../../../arch1/arch14"?"../../../../../../foo/foo2/foo3/arch1/arch14"?= g --=20 public gpg key id: AE60F64C