From owner-freebsd-questions@FreeBSD.ORG Fri Feb 6 22:56:23 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 166E21065673 for ; Fri, 6 Feb 2009 22:56:23 +0000 (UTC) (envelope-from dan@dan.emsphone.com) Received: from email1.allantgroup.com (email1.emsphone.com [199.67.51.115]) by mx1.freebsd.org (Postfix) with ESMTP id C61A28FC12 for ; Fri, 6 Feb 2009 22:56:22 +0000 (UTC) (envelope-from dan@dan.emsphone.com) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by email1.allantgroup.com (8.14.0/8.14.0) with ESMTP id n16MuLbU068892 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 6 Feb 2009 16:56:21 -0600 (CST) (envelope-from dan@dan.emsphone.com) Received: from dan.emsphone.com (smmsp@localhost [127.0.0.1]) by dan.emsphone.com (8.14.3/8.14.3) with ESMTP id n16MuL2x038097 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 6 Feb 2009 16:56:21 -0600 (CST) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.14.3/8.14.3/Submit) id n16MuJGt038064; Fri, 6 Feb 2009 16:56:19 -0600 (CST) (envelope-from dan) Date: Fri, 6 Feb 2009 16:56:19 -0600 From: Dan Nelson To: Adam Vande More Message-ID: <20090206225619.GA75180@dan.emsphone.com> References: <498CBEBE.7080702@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <498CBEBE.7080702@gmail.com> X-OS: FreeBSD 7.1-STABLE User-Agent: Mutt/1.5.18 (2008-05-17) X-Virus-Scanned: ClamAV version 0.94.1, clamav-milter version 0.94.1 on email1.allantgroup.com X-Virus-Status: Clean X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.0.2 (email1.allantgroup.com [199.67.51.78]); Fri, 06 Feb 2009 16:56:21 -0600 (CST) X-Scanned-By: MIMEDefang 2.45 Cc: freebsd-questions@freebsd.org Subject: Re: insert new line in files X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 Feb 2009 22:56:23 -0000 In the last episode (Feb 06), Adam Vande More said: > I want to insert a new line of text at a certain position in certain files > recursively under a directory. More specifically, I want text like this: > > include('/usr/home/www/imp-sites/default_inventory.php'); > > to be put into file X at line 37 where file X appears in ./subdir1, > .subdir2 etc. There are many subdirs or I'd just do it by hand. > > I've done stuff like this before with the rpl script and it works well as > long as there aren't any special characters in the strings. So I assumed > I finally hit the point where I'm forced to learn something like sed or > awk and tried some examples with sed but I can't figure out what I'm doing > wrong. > > I get results like this: > > sed '5i\test' test.txt > sed: 1: "5i\test": extra characters after \ at the end of i command You want: sed -e '5i\ test' test.txt i.e. a linebreak after the backslash. -- Dan Nelson dnelson@allantgroup.com