From owner-freebsd-questions@FreeBSD.ORG Mon Jun 18 09:29:24 2007 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 6C4F616A41F for ; Mon, 18 Jun 2007 09:29:24 +0000 (UTC) (envelope-from nvass@teledomenet.gr) Received: from wmail.teledomenet.gr (wmail.teledomenet.gr [213.142.128.16]) by mx1.freebsd.org (Postfix) with ESMTP id EDF1213C45D for ; Mon, 18 Jun 2007 09:29:23 +0000 (UTC) (envelope-from nvass@teledomenet.gr) Received: from iris (unknown [192.168.1.71]) by wmail.teledomenet.gr (Postfix) with ESMTP id 2DEF71C8D0B; Mon, 18 Jun 2007 12:29:22 +0300 (EEST) From: Nikos Vassiliadis To: Olivier Regnier Date: Mon, 18 Jun 2007 12:28:40 +0300 User-Agent: KMail/1.9.1 References: <467269EE.6090001@oregnier.net> <467284F9.7090005@oregnier.net> <4673E72A.3050706@oregnier.net> In-Reply-To: <4673E72A.3050706@oregnier.net> X-NCC-RegID: gr.telehouse MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-7" Content-Transfer-Encoding: 8bit Content-Disposition: inline Message-Id: <200706181228.41947.nvass@teledomenet.gr> Cc: freebsd-questions@freebsd.org Subject: Re: problem with sed command and csh 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: Mon, 18 Jun 2007 09:29:24 -0000 On Saturday 16 June 2007 16:35, Olivier Regnier wrote: > Olivier Regnier a écrit : > > Nikos Vassiliadis a écrit : > >> On Friday 15 June 2007 13:29, Olivier Regnier wrote: > >>> Hi everybody, > >>> > >>> Actually, i'm working on FreeBSD 6.2 and csh shell. With a sh > >>> script, i trying to execute this command : > >>> sed -e "s/MAKE_ARGS\([^{]*\){/MAKE_ARGS\1{\n\t'mail/nbsmtp' => > >>> 'WITH_IPV6=1 WITH_SSL=1',/" > /usr/local/etc/pkgtools.conf > >>> > >>> The result is not correct, i have an error : > >>> sed: 1: "s/MAKE_ARGS\([^{]*\){/M . . .": bad flag in subsitute > >>> command: 'n' > >>> > >>> Can you help me please ? > >> > >> s/MAKE_ARGS\([^{]*\){/MAKE_ARGS\1{\n\t'mail/nbsmtp' => > >> This n is invalid--------------------------^^^ > >> > >> You should add a backslash before each slash > >> that is not used as a separator for the s command. > >> E.g. > >> s/I want to substitute the \/ character/with the _ character/ > >> s/\/\/\//three slashes/ > >> > >> You can also use a separator of choice for the s command. > >> That is: > >> s/foo/bar/ is equivalent to s@foo@bar@ > >> is equivalent to sAfooAbarA > >> is equivalent to s1foo1bar1. > >> > >> keep in mind, that our sed might not be > >> totally compatible with GNU sed. > >> > >> HTH, Nikos > > > > Thank for you anserw but the result is bad again :) > > I tryed this : sed > > "s/MAKE_ARGS\([^{]*\){/MAKE_ARGS\1{\n\t'mail\/nbsmtp' => 'WITH_IPV6=1 > > WITH_SSL=1',/" > /usr/local/etc/pkgtools.conf > > but i have this with cat /usr/local/etc/pkgtools.conf > > > > MAKE_ARGS = {nt'mail/nbsmtp' => 'WITH_IPV6=1 WITH_SSL=1', > > } > > > > Sed and csh is strange no ? I think \n \t not supported by csh. > > well yesterday i tried with awk command : > echo MAKE_ARGS = { | awk '{ sub(/MAKE_ARGS = {/, "MAKE_ARGS = > {\n\t\'\'ports-mgmtp/portupgrade' => > \'\'WITH_BDB4=1',\n\t\'\'sysutils/fastest_cvsup' => > \'\'WITH_ROUNDTRIP=1',\n\t\'\'mail/nbsmtp' =>'WITH_IPV6=1" > "WITH_SSL=1',\n}"); print; }' > > The resultat is not bad but incomplete : > > MAKE_ARGS = { > 'ports-mgmtp/portupgrade => 'WITH_BDB4=1, > 'sysutils/fastest_cvsup => 'WITH_ROUNDTRIP=1, > 'mail/nbsmtp => 'WITH_IPV6=1 WITH_SSL=1, > } > > > I should have that : > > MAKE_ARGS = { > 'ports-mgmtp/portupgrade*'* => 'WITH_BDB4=1*'*, > 'sysutils/fastest_cvsup*'* => 'WITH_ROUNDTRIP=1*'*, > 'mail/nbsmtp*'* => 'WITH_IPV6=1 WITH_SSL=1*'*, > } > Single quotes(') have special meaning to the shell. You have to cancel the special meaning using backslashes. For example: %set a = foo\'bar %echo $a foo'bar %set a = foo\"bar %echo $a foo"bar As I see in your code above, not every single quote is backslashed. Asterisks should be backslashed in order to passed literally to awk. awk has also special characters, which also should be backslashed to be treated as simple characters. For example(bash, not csh): nik:0:~$ echo | awk '{ print("foo\"bar") }' foo"bar It gets complicated since some characters are special to both, csh and awk. Frequently, you have to use backslashed backslashes, to get the wanted result... You should check the csh and awk manual page. Last but not least, do you have use csh? It's not recommend for scripting. HTH, Nikos