From owner-freebsd-questions@FreeBSD.ORG Fri May 1 20:20:29 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 47BCF280 for ; Fri, 1 May 2015 20:20:29 +0000 (UTC) Received: from mail-ig0-x233.google.com (mail-ig0-x233.google.com [IPv6:2607:f8b0:4001:c05::233]) (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 1332F1775 for ; Fri, 1 May 2015 20:20:29 +0000 (UTC) Received: by igblo3 with SMTP id lo3so46820962igb.1 for ; Fri, 01 May 2015 13:20:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=gT7Mf4a5OGnvqGkNE98OPRaeqOgTPnebr1hNAliLVnI=; b=BYdmzysHW3MctIWt8t0L6ynWKEeiUOW3nin8WJwl1euEE/jmPkxM3HqKVAxTcWKKfW Rh85SAL5iQD4SkpJAKco031WFwrAIoqymO7Kj6OOYQQF9NH4WqfsbTeSURWHFBRPIRPc 9uYBK40WWiasQUXUgBNG3xR7EOcpiSG5CwuT9NcEQbWTRGw9dZ0PMqJeW3XmW035O1dN CpeALtpCSAa49iJYBxd1fmlkcTWphH+r3EnQRB+CGUiaz/4ZXw7/QCMvAvIohyHcvMLV MAQFaM00FUGiPWup/lGTPAYXELo6F2hY5EqGjBjFgXXzKuVIsvUYIvpxiQeAXE/jxJM2 1jNw== X-Received: by 10.50.176.137 with SMTP id ci9mr12736340igc.2.1430511628235; Fri, 01 May 2015 13:20:28 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.131.194 with HTTP; Fri, 1 May 2015 13:20:07 -0700 (PDT) In-Reply-To: References: From: Alex Merritt Date: Fri, 1 May 2015 16:20:07 -0400 Message-ID: Subject: Re: Find and replace content in 100 lines To: Nancy Belle Cc: freebsd-questions Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.20 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 20:20:29 -0000 Hello Nancy, On Thu, Apr 30, 2015 at 8:58 PM, Nancy Belle wrote: > > 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. > You want sed with the search/replace feature, generally: sed s/regular expression/replacement/flags like so sed -i .orig 's:"../../../arch1/arch14":"../../../../../../foo/foo2/foo3/arch1/arch14":g' input.html Those single quotes are important, to prevent the shell from doing any interpretation within anything enclosed between them (e.g. environment variables, if there were any, and from removing the double quotes). The single quotes aren't important to sed. The colon (a forward slash in the example) is the delimiter character, and can be any character you like (except backslash and newline). Pick one which does not appear in your strings you are searching and replacing. -i tells sed to edit the file directly, first making a copy with the given extension as the backup. Hope this helps, Alex