sed - output lines with one word
Josh McFarlane <[email protected]>
| Newsgroups | gmane.comp.gnu.utils.bugs |
|---|---|
| Message-ID | <CAGnr9c5m2x4Vr5aWRTnVVa1w86VUMH+6EMgcLztRPhXY8AB8ww@mail.gmail.com> |
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. Also see my post on http://stackoverflow.com/a/11008739/1452839 for an intermediate fix. 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: <[email protected]> <[email protected]>. Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.