bug#10030: grep: strange behavior with '-' in character class
Hi, On 11/12/2011 08:05 PM, Thomas Dignan wrote: echo /lib64/ld-linux-x86-64.so.2 | grep -o '[a-zA-Z\/0-9\-\.]*' You probably want to use something like echo /lib64/ld-linux-x86-64.so.2 | grep -o '[-a-zA-Z/0-9.]*' Note: The '-' should be the first character inside a character class if it is not used to describe a range. Erik
bug#10030: grep: strange behavior with '-' in character class
Hello Coreutils Team, When I use the command: echo /lib64/ld-linux-x86-64.so.2 | grep -o '[a-zA-Z\/0-9\-\.]*' The result is that I get a tokenized string where - has been replaced with \n /lib64/ld linux x86 64.so.2 The expected result is: /lib64/ld-linux-x86-64.so.2 When the character class is modified so that the - is not next to the number 9: echo /lib64/ld-linux-x86-64.so.2 | grep -o '[a-zA-Z\/0-9\.\-]*' /lib64/ld-linux-x86-64.so.2 The expected result is obtained. I am aware - is used to specify a range, but it is escaped, should this be the proper behaviour? Thanks, Tom
bug#10030: grep: strange behavior with '-' in character class
I have since learned that you are not supposed to escape things within brackets at all and simply position them so they have relevant meaning, and that dot does not need to be escaped inside brackets. Not sure if my mail is still relevant. On 11/12/2011 02:05 PM, Thomas Dignan wrote: Hello Coreutils Team, When I use the command: echo /lib64/ld-linux-x86-64.so.2 | grep -o '[a-zA-Z\/0-9\-\.]*' The result is that I get a tokenized string where - has been replaced with \n /lib64/ld linux x86 64.so.2 The expected result is: /lib64/ld-linux-x86-64.so.2 When the character class is modified so that the - is not next to the number 9: echo /lib64/ld-linux-x86-64.so.2 | grep -o '[a-zA-Z\/0-9\.\-]*' /lib64/ld-linux-x86-64.so.2 The expected result is obtained. I am aware - is used to specify a range, but it is escaped, should this be the proper behaviour? Thanks, Tom
bug#10030: grep: strange behavior with '-' in character class
tags 10030 + notabug close 10030 thanks Thomas Dignan wrote: I have since learned that you are not supposed to escape things within brackets at all and simply position them so they have relevant meaning, and that dot does not need to be escaped inside brackets. That's right. You have it. Not sure if my mail is still relevant. Well... Not really. But mostly because you sent your bug report to bug-coreutils instead of bug-grep. Wrong bug list! Since you have it figured out and it is the wrong list I am going to go ahead and mark the bug as closed. You can follow up with bug-grep if you have another report. Bob