Re: problem with sed command and csh

2007-06-19 Thread Giorgos Keramidas
On 2007-06-18 12:28, Nikos Vassiliadis [EMAIL PROTECTED] wrote:
 Last but not least, do you have use csh?  It's not recommend for
 scripting.

This must be the most sensible thing I've read in the entire thread.

Quoting rules aside, tcsh is a nice interactive shell, but there are far
too many annoyances in the expansion rules, and differences between what
one has to type in an interactive shell prompt and in a script.

If you have a choice, please use /bin/sh, bash or ksh :-)


___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: problem with sed command and csh

2007-06-19 Thread Giorgos Keramidas
On 2007-06-18 11:33, Olivier Regnier [EMAIL PROTECTED] wrote:
 I founded solution with awk command and that works well.

 cat /usr/local/etc/pkgtools.conf | awk '{ sub(/^[ \t]*MAKE_ARGS = {/, 
 \n\t\x27ports-mgmtp/portupgrade\x27 = 
 \x27WITH_BDB4=1\x27,\n\t\x27sysutils/fastest_csvsup\x27 = 
 \x27WITH_ROUNDTRIP=1\x27,\n\t\x27mail/nbsmtp\x27 = \x27WITH_IPV6=1 
 WITH_SSL=1\x27,\n); print; }'  /usr/local/etc/pkgtools.conf

I'm sure you really do *NOT* want to read and write to the same file in
a single shell pipeline.  Watch out for the cookie monster which feeds
on the remains of zeroed out files :-P

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: problem with sed command and csh

2007-06-18 Thread Nikos Vassiliadis
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 [EMAIL PROTECTED]@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
foobar

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) }'
foobar

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
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: problem with sed command and csh

2007-06-18 Thread Olivier Regnier

Nikos Vassiliadis a écrit :

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 [EMAIL PROTECTED]@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
foobar

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) }'
foobar

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
  

Hello,

I founded solution with awk command and that works well.

cat /usr/local/etc/pkgtools.conf | awk '{ sub(/^[ \t]*MAKE_ARGS = {/, 
\n\t\x27ports-mgmtp/portupgrade\x27 = 
\x27WITH_BDB4=1\x27,\n\t\x27sysutils/fastest_csvsup\x27 = 
\x27WITH_ROUNDTRIP=1\x27,\n\t\x27mail/nbsmtp\x27 = \x27WITH_IPV6=1 
WITH_SSL=1\x27,\n); print; }'  /usr/local/etc/pkgtools.conf


Thank you :)
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: problem with sed command and csh

2007-06-15 Thread Nikos Vassiliadis
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 [EMAIL PROTECTED]@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
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: problem with sed command and csh

2007-06-15 Thread Olivier Regnier

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 [EMAIL PROTECTED]@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.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: problem with sed command and csh

2007-06-15 Thread Nikos Vassiliadis
On Friday 15 June 2007 15:24, Olivier Regnier wrote:
 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 [EMAIL PROTECTED]@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.

No, its sed. You cannot use backslash notation with
BSD sed.
nik:0:~$ sed s/foo/\t\n/
foo
tn

You can use a literal tab character, but not a literal
newline character...

How about this?
nik:0:~$ echo foo | awk '{ sub(/foo/, foo\n\tbar); print; }'
foo
bar

HTH, Nikos
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: problem with sed command and csh

2007-06-15 Thread Garrett Cooper

Nikos Vassiliadis wrote:

On Friday 15 June 2007 15:24, Olivier Regnier wrote:
  

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 [EMAIL PROTECTED]@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.



No, its sed. You cannot use backslash notation with
BSD sed.
nik:0:~$ sed s/foo/\t\n/
foo
tn

You can use a literal tab character, but not a literal
newline character...

How about this?
nik:0:~$ echo foo | awk '{ sub(/foo/, foo\n\tbar); print; }'
foo
bar

HTH, Nikos
  
   Note: Using (t)csh as a part of any text manipulation operation I've 
discovered is generally a bad idea. When using sed, perl, or (g)awk, I 
always use (ba)sh, because (t)csh does some nasty evaluation of inline 
expressions, whereas (ba)sh doesn't. Just try using an expression with 
an exclamation point, for example :).
   Also for most strings, I'd get in the habit of quoting with single 
quotes instead of double quotes, if at all possible, because sometimes 
shells and other programs evaluate double quoted arguments differently 
than single quoted arguments.

-Garrett
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]