Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 7 Feb 2009 01:13:19 +0100
From:      Polytropon <freebsd@edvax.de>
To:        Adam Vande More <amvandemore@gmail.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: insert new line in files
Message-ID:  <20090207011319.ec742f0f.freebsd@edvax.de>
In-Reply-To: <498CBEBE.7080702@gmail.com>
References:  <498CBEBE.7080702@gmail.com>

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 <amvandemore@gmail.com> 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).





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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090207011319.ec742f0f.freebsd>