bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

sed - output lines with one word


From: Josh McFarlane
Subject: sed - output lines with one word
Date: Wed, 13 Jun 2012 15:02:56 +1000

I believe I have found a potential bug in sed extended regular
expressions. I was trying to output lines containing only one word
from a text file. However, I found my expression to match more than it
should have.
Using the following command:
$sed -n -r '/^\s*[^\s]+\s*$/p' test.txt

Where test.txt conatins:
a
         b
a b

Produces the following output:
 a
         b
a b

In my opinion this is an unexpected behavior as this regular
expression should only print lines where there is zero or more
whitespace characters, followed by one or more non whitespace
characters, followed by zero or more whitespace characters, followed
by the end of the line.

I hope that this was of help.
Regards,
Josh McFarlane.

$ sed --version
GNU sed version 4.2.1
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE,
to the extent permitted by law.

GNU sed home page: <http://www.gnu.org/software/sed/>
<http://www.gnu.org/software/sed/>.
General help using GNU software: <http://www.gnu.org/gethelp/>
<http://www.gnu.org/gethelp/>.
E-mail bug reports to: <address@hidden> <address@hidden>.
Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]