Date: Fri, 6 Feb 2009 17:21:40 -0600 From: Dan Nelson <dnelson@allantgroup.com> To: Adam Vande More <amvandemore@gmail.com> Cc: freebsd-questions@freebsd.org Subject: Re: insert new line in files Message-ID: <20090206232129.GB75180@dan.emsphone.com> In-Reply-To: <498CC0FC.1040706@gmail.com> References: <498CBEBE.7080702@gmail.com> <20090206225619.GA75180@dan.emsphone.com> <498CC0FC.1040706@gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
In the last episode (Feb 06), Adam Vande More said: > Dan Nelson wrote: > > 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. > > I had actually tried that too: > > > sed -e '5i\ > ? test' text.txt > sed: 1: "5i > test > ": command i expects \ followed by text I don't see a backslash in the error message, which means something ate it. Are you running this command from something other than the commandline or a plain sh script? If you're calling this from another scripting language (via system() or popen() or something similar), you probably have to double the backslash so whatever's parsing it out passes one through to sed. -- Dan Nelson dnelson@allantgroup.com
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090206232129.GB75180>