Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 7 Feb 2009 01:13:19 +0100
From:      Polytropon <>
To:        Adam Vande More <>
Subject:   Re: insert new line in files
Message-ID:  <>
In-Reply-To: <>
References:  <>

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help
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"); }' <file>

It may be neccessary to have a look at the multiple ' (awk skript enclosure,
include() parameter enclusure).

>From Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...

Want to link to this message? Use this URL: <>