From owner-freebsd-questions@FreeBSD.ORG Fri Feb 6 22:50:35 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 48C411065727 for ; Fri, 6 Feb 2009 22:50:35 +0000 (UTC) (envelope-from amvandemore@gmail.com) Received: from imedmobility.com (host-50.216-16-29.iw.net [216.16.29.50]) by mx1.freebsd.org (Postfix) with ESMTP id 25C588FC16 for ; Fri, 6 Feb 2009 22:50:35 +0000 (UTC) (envelope-from amvandemore@gmail.com) Received: from midco.net (host-47-73-107-208.midco.net [208.107.73.47]) by imedmobility.com (Postfix) with ESMTP id 4C4161173C59 for ; Fri, 6 Feb 2009 16:50:34 -0600 (CST) Message-ID: <498CBEBE.7080702@gmail.com> Date: Fri, 06 Feb 2009 22:50:38 +0000 From: Adam Vande More User-Agent: Thunderbird 2.0.0.18 (X11/20081225) MIME-Version: 1.0 To: freebsd-questions@freebsd.org Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: 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:50:35 -0000 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 Is sed the right tool for this? If so, any good primers for BSD sed?