From owner-freebsd-questions@FreeBSD.ORG Sat Feb 7 00:13:27 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 4A7CA1065672 for ; Sat, 7 Feb 2009 00:13:27 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx02.qsc.de (mx02.qsc.de [213.148.130.14]) by mx1.freebsd.org (Postfix) with ESMTP id 0B14E8FC1B for ; Sat, 7 Feb 2009 00:13:26 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from r55.edvax.de (port-92-196-52-176.dynamic.qsc.de [92.196.52.176]) by mx02.qsc.de (Postfix) with ESMTP id 8EE3B16C031C; Sat, 7 Feb 2009 01:13:25 +0100 (CET) Received: from r55.edvax.de (localhost [127.0.0.1]) by r55.edvax.de (8.14.2/8.14.2) with SMTP id n170DJY6001578; Sat, 7 Feb 2009 01:13:20 +0100 (CET) (envelope-from freebsd@edvax.de) Date: Sat, 7 Feb 2009 01:13:19 +0100 From: Polytropon To: Adam Vande More Message-Id: <20090207011319.ec742f0f.freebsd@edvax.de> In-Reply-To: <498CBEBE.7080702@gmail.com> References: <498CBEBE.7080702@gmail.com> Organization: EDVAX X-Mailer: Sylpheed 2.4.7 (GTK+ 2.12.1; i386-portbld-freebsd7.0) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 Reply-To: Polytropon List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 07 Feb 2009 00:13:27 -0000 Just as a possible starting point... On Fri, 06 Feb 2009 22:50:38 +0000, Adam Vande More wrote: > 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. > > [...] > > Is sed the right tool for this? If so, any good primers for BSD sed? I'd suggest awk. If you have already a mechanism to "handle" each of the files that need alteration, an awk command could be this: awk '{ print $0; if(NR == 37) printf("include('/usr/home/www/imp-sites/default_inventory.php');\n"); }' It may be neccessary to have a look at the multiple ' (awk skript enclosure, include() parameter enclusure). -- Polytropon >From Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...