Re: sed error unescaped newline inside substitute pattern

2009-03-14 Thread Mike Clarke
On Friday 13 March 2009, David Banning wrote:

 Yes - I have control of that - so I could filter out the problem in
 php. The only problem is that I don't know what I am filtering.
 If I know exactly what the erroneous characters are I could filter
 them - I have looked at the file in vi but the problematic characters
 are invisible there.

Would the php addcslashes() function do what you need?

?php
$in = This
is
the
input
from the
web server;
$out = addcslashes($in,\n);
var_dump ($out);
?

This results in:

string(42) This\nis\nthe\ninput\nfrom the\nweb server 

-- 
Mike Clarke
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: sed error unescaped newline inside substitute pattern

2009-03-13 Thread Nikos Vassiliadis

David Banning wrote:

Here is the php line that gives the error;

cat start_text | sed s/--maintext--/$test/  endtext

give error;

sed: 1: s/--maintext--/ Comment ...: unescaped newline inside substitute 
pattern

where $test contains customer input from a website form

There is something about the content of the text within the variable $test that 
is causing the error.

Any pointers would be helpful.


You cannot use unescaped newlines in the replacement string:
# sed 's/foo/fooPress enter here
 bar/'
sed: 1: s/foo/foo
bar/: unescaped newline inside substitute pattern

You have to precede each newline character with a backslash:
# sed 's/foo/foo\Press enter here
 bar/'
foo
foo
bar

The examples above are made using the bourne shell. The
above doesn't work in csh.

It's the documented behavior:
 2.   The escape sequence \n matches a newline character embedded in the
 pattern space.  You cannot, however, use a literal newline character
 in an address or in the substitute command.

 ...

 A line can be split by substituting a newline character into it.
 To specify a newline character in the replacement string, precede
 it with a backslash.

I am sure there is some good reason behind this...

OT, you should not pass parameters to shell scripts
using double quotes, since the shell will evaluate
possible variable values:
# echo $OSTYPE
FreeBSD
# echo '$OSTYPE'
$OSTYPE

I really doubt you want the first behavior, that is, variable
evaluation for strings coming from a web server.

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


Re: sed error unescaped newline inside substitute pattern

2009-03-13 Thread David Banning

Nikos Vassiliadis wrote:

David Banning wrote:

Here is the php line that gives the error;

cat start_text | sed s/--maintext--/$test/  endtext

give error;

sed: 1: s/--maintext--/ Comment ...: unescaped newline inside 
substitute pattern


where $test contains customer input from a website form

There is something about the content of the text within the variable 
$test that is causing the error.


Any pointers would be helpful.


You cannot use unescaped newlines in the replacement string:
# sed 's/foo/fooPress enter here
 bar/'
sed: 1: s/foo/foo
bar/: unescaped newline inside substitute pattern

You have to precede each newline character with a backslash:
# sed 's/foo/foo\Press enter here
 bar/'
foo
foo
bar

The examples above are made using the bourne shell. The
above doesn't work in csh.

It's the documented behavior:
 2.   The escape sequence \n matches a newline character embedded in the
 pattern space.  You cannot, however, use a literal newline character
 in an address or in the substitute command.

 ...

 A line can be split by substituting a newline character into it.
 To specify a newline character in the replacement string, precede
 it with a backslash.

I am sure there is some good reason behind this...

OT, you should not pass parameters to shell scripts
using double quotes, since the shell will evaluate
possible variable values:
# echo $OSTYPE
FreeBSD
# echo '$OSTYPE'
$OSTYPE

I really doubt you want the first behavior, that is, variable
evaluation for strings coming from a web server.

HTH, Nikos
The problem that I am having is that the input is from a web form - so I 
have to deal with it - I have to somehow modify it so it can pass sed.

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


Re: sed error unescaped newline inside substitute pattern

2009-03-13 Thread Nikos Vassiliadis

David Banning wrote:

Nikos Vassiliadis wrote:

David Banning wrote:

Here is the php line that gives the error;

cat start_text | sed s/--maintext--/$test/  endtext

give error;

sed: 1: s/--maintext--/ Comment ...: unescaped newline inside 
substitute pattern


where $test contains customer input from a website form

There is something about the content of the text within the variable 
$test that is causing the error.


Any pointers would be helpful.


You cannot use unescaped newlines in the replacement string:
# sed 's/foo/fooPress enter here
 bar/'
sed: 1: s/foo/foo
bar/: unescaped newline inside substitute pattern

You have to precede each newline character with a backslash:
# sed 's/foo/foo\Press enter here
 bar/'
foo
foo
bar

The examples above are made using the bourne shell. The
above doesn't work in csh.

It's the documented behavior:
 2.   The escape sequence \n matches a newline character embedded in the
 pattern space.  You cannot, however, use a literal newline character
 in an address or in the substitute command.

 ...

 A line can be split by substituting a newline character into it.
 To specify a newline character in the replacement string, precede
 it with a backslash.

I am sure there is some good reason behind this...

OT, you should not pass parameters to shell scripts
using double quotes, since the shell will evaluate
possible variable values:
# echo $OSTYPE
FreeBSD
# echo '$OSTYPE'
$OSTYPE

I really doubt you want the first behavior, that is, variable
evaluation for strings coming from a web server.

HTH, Nikos
The problem that I am having is that the input is from a web form - so I 
have to deal with it - I have to somehow modify it so it can pass sed.


Don't you have control over this web form??? That's the place
you should filter your input... The sooner you do the filtering
the better.

Anyway, you could also use an intermediate variable that replaces
all newlines with spaces.

# a=This
 is
 the
 input
 from the
 web server
# b=`echo $a`
# sed s/foo/$b/
foo
This is the input from the web server
^D#

I hope you won't go that route though... Nikos

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


Re: sed error unescaped newline inside substitute pattern

2009-03-13 Thread Nikos Vassiliadis

David Banning wrote:
I have looked at the file in vi but the problematic characters are 
invisible there.


The problematic character is the newline character, \n, ASCII 0xA.

And, yes vi is old but it's a few months now that it supports newlines
without problems;)

Nikos



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


Re: sed error unescaped newline inside substitute pattern

2009-03-13 Thread David Banning




Don't you have control over this web form??? That's the place
you should filter your input... The sooner you do the filtering
the better.

Anyway, you could also use an intermediate variable that replaces
all newlines with spaces.

# a=This
 is
 the
 input
 from the
 web server
# b=`echo $a`
# sed s/foo/$b/
foo
This is the input from the web server
^D#

I hope you won't go that route though... Nikos

Yes - I have control of that - so I could filter out the problem in php. 
The only problem is that I don't know what I am filtering.
If I know exactly what the erroneous characters are I could filter them 
- I have looked at the file in vi but the problematic characters are 
invisible there.

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


sed error unescaped newline inside substitute pattern

2009-03-12 Thread David Banning
Here is the php line that gives the error;

cat start_text | sed s/--maintext--/$test/  endtext

give error;

sed: 1: s/--maintext--/ Comment ...: unescaped newline inside substitute 
pattern

where $test contains customer input from a website form

There is something about the content of the text within the variable $test that 
is causing the error.

Any pointers would be helpful.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: sed error unescaped newline inside substitute pattern

2009-03-12 Thread Kent Stewart
On Thursday 12 March 2009 10:34:36 am David Banning wrote:
 Here is the php line that gives the error;

 cat start_text | sed s/--maintext--/$test/  endtext

 give error;

 sed: 1: s/--maintext--/ Comment ...: unescaped newline inside substitute
 pattern

 where $test contains customer input from a website form

 There is something about the content of the text within the variable $test
 that is causing the error.

 Any pointers would be helpful.

Well, it might be because test is a command line function.

Kent

-- 
kent Stewart
Richland, WA

http://users.owt.com/kstewart/index.html

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


Re: sed error unescaped newline inside substitute pattern

2009-03-12 Thread David Banning
 Well, it might be because test is a command line function.

It actually doesn't matter whether I use the word test or any other word as a 
variable
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: sed error unescaped newline inside substitute pattern

2009-03-12 Thread Frank Shute
On Thu, Mar 12, 2009 at 01:34:36PM -0400, David Banning wrote:

 Here is the php line that gives the error;
 
 cat start_text | sed s/--maintext--/$test/  endtext
 
 give error;
 
 sed: 1: s/--maintext--/ Comment ...: unescaped newline inside substitute 
 pattern
 
 where $test contains customer input from a website form
 
 There is something about the content of the text within the variable $test 
 that is causing the error.
 
 Any pointers would be helpful.

I think your problem is that $ is an end of line as a regex. So sed is
choking on the fact that there's some text (test) after the end of
line.

I can't really tell you how to fix it, although backslash escaping the
$ might be worth a try.

Regards,

-- 

 Frank 


 Contact info: http://www.shute.org.uk/misc/contact.html 

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