People,
This behaves as expected:
echo 'This is a test 12335 and 669384 535xy4' | sed 's/[0-9]*//g'
but I would expect this:
echo 'This is a test 12335 and 669384 535xy4' | sed 's/[0-9]*//'
to delete the first string of digits but it doesn't do anything . . clarification from a sed guru?
Thanks,
Phil.
On Tue, May 3, 2016 at 10:44 PM, Philip Rhoades phil@pricom.com.au wrote:
People,
This behaves as expected:
echo 'This is a test 12335 and 669384 535xy4' | sed 's/[0-9]*//g'
but I would expect this:
echo 'This is a test 12335 and 669384 535xy4' | sed 's/[0-9]*//'
to delete the first string of digits but it doesn't do anything . . clarification from a sed guru?
Thanks,
Phil.
Philip Rhoades
What about adding the "g" qualifier and substituting "*" for "+"? I didn't try this, just wondering...sed 's/[0-9+]//g'
HIH, Ken Wolcott
On 05/04/2016 12:44 AM, Philip Rhoades wrote:
People,
This behaves as expected:
echo 'This is a test 12335 and 669384 535xy4' | sed 's/[0-9]*//g'
but I would expect this:
echo 'This is a test 12335 and 669384 535xy4' | sed 's/[0-9]*//'
to delete the first string of digits but it doesn't do anything . . clarification from a sed guru?
[0-9]* means zero or more digits. [0-9][0-9]* would be one or more digits
David
Thanks,
Phil.
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256
On 2016/5/4 15:50, dwoody5654 wrote:
On 05/04/2016 12:44 AM, Philip Rhoades wrote:
People,
This behaves as expected:
echo 'This is a test 12335 and 669384 535xy4' | sed 's/[0-9]*//g'
but I would expect this:
echo 'This is a test 12335 and 669384 535xy4' | sed 's/[0-9]*//'
to delete the first string of digits but it doesn't do anything . . clarification from a sed guru?
[0-9]* means zero or more digits. [0-9][0-9]* would be one or more digits
David
Then the command line would be echo 'This is a test 12335 and 669384 535xy4' | sed 's/[0-9]+//' to remove the first string of digits.
Thanks,
Phil.
-- users mailing list users@lists.fedoraproject.org To unsubscribe or change subscription options: http://lists.fedoraproject.org/admin/lists/users@lists.fedoraproject.o
rg
Fedora Code of Conduct: http://fedoraproject.org/code-of-conduct
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines Have a question? Ask away: http://ask.fedoraproject.org
On Wed, May 04, 2016 at 03:44:26PM +1000, Philip Rhoades wrote:
People,
This behaves as expected:
echo 'This is a test 12335 and 669384 535xy4' | sed 's/[0-9]*//g'
but I would expect this:
echo 'This is a test 12335 and 669384 535xy4' | sed 's/[0-9]*//'
to delete the first string of digits but it doesn't do anything . . clarification from a sed guru?
The '*' means "zero or more digits". Don't forget that zero. The first match is where there are zero digits, i.e. at the beginning of the line. So sed replaces it with "//" (nothing).
Try sed 's/[0-9]*/X/' to confirm.
You really want sed 's/[0-9][0-9]*//' which reads a digit followed by zero or more additional digits.
jl
On 05/04/2016 10:09 AM, Jon LaBadie wrote:
The '*' means "zero or more digits". Don't forget that zero. The first match is where there are zero digits, i.e. at the beginning of the line. So sed replaces it with "//" (nothing).
However, usually regexps are greedy so they match as much as possible, not the minimum. And somehow it does work when you use /g so it is matching more.
Try sed 's/[0-9]*/X/' to confirm.
You really want sed 's/[0-9][0-9]*//' which reads a digit followed by zero or more additional digits.
Or use + as has been mentioned elsewhere in this thread.
On Wed, May 04, 2016 at 10:42:20AM -0700, Samuel Sieb wrote:
On 05/04/2016 10:09 AM, Jon LaBadie wrote:
The '*' means "zero or more digits". Don't forget that zero. The first match is where there are zero digits, i.e. at the beginning of the line. So sed replaces it with "//" (nothing).
However, usually regexps are greedy so they match as much as possible, not the minimum. And somehow it does work when you use /g so it is matching more.
Try sed 's/[0-9]*/X/' to confirm.
You really want sed 's/[0-9][0-9]*//' which reads a digit followed by zero or more additional digits.
Or use + as has been mentioned elsewhere in this thread.
Traditionally sed has used basic RE syntax not the extended syntax that includes "+". If the OP uses a sed such as exists on my systems, you can get extended RE syntax with the "-r" option.
sed -r 's/[0-9]+//'
Samuel, does your sed support extended REs by default? If so, what system has that version?
jl
On 05/04/2016 11:32 AM, Jon LaBadie wrote:
Traditionally sed has used basic RE syntax not the extended syntax that includes "+". If the OP uses a sed such as exists on my systems, you can get extended RE syntax with the "-r" option.
sed -r 's/[0-9]+//'Samuel, does your sed support extended REs by default? If so, what system has that version?
I'm on Fedora 23 and yes, it supports it by default. Although the + does need to be escaped like with grep. I sent an earlier reply in this thread, but it only went to the sender, not the list...
sed 's/[0-9]+//'
Samuel Sieb, Wed, 4 May 2016 10:42:20 -0700:
On 05/04/2016 10:09 AM, Jon LaBadie wrote:
The '*' means "zero or more digits". Don't forget that zero. The first match is where there are zero digits, i.e. at the beginning of the line. So sed replaces it with "//" (nothing).
However, usually regexps are greedy so they match as much as possible, not the minimum.
And that's what it does. It matches the empty string at the beginning of the line - and it would also (greedily) match digits at the beginning of the line, but there are none. Try echo '123This is a test 12335 and 669384 535xy4' | sed 's/[0-9]*//'
And somehow it does work when you use /g so it is matching more.
No, it's not matching *more*, it's matching *again* (that's exactly what the g flag tells it to).
On 05/04/2016 03:29 PM, Markus Schönhaber wrote:
Samuel Sieb, Wed, 4 May 2016 10:42:20 -0700:
On 05/04/2016 10:09 AM, Jon LaBadie wrote:
The '*' means "zero or more digits". Don't forget that zero. The first match is where there are zero digits, i.e. at the beginning of the line. So sed replaces it with "//" (nothing).
However, usually regexps are greedy so they match as much as possible, not the minimum.
And that's what it does. It matches the empty string at the beginning of the line - and it would also (greedily) match digits at the beginning of the line, but there are none. Try echo '123This is a test 12335 and 669384 535xy4' | sed 's/[0-9]*//'
Oh, right. I never use a regexp that can match nothing, so I missed that. :-)
On 5 May 2016 at 10:27, Patrick O'Callaghan pocallaghan@gmail.com wrote:
On Wed, 2016-05-04 at 16:24 -0700, Samuel Sieb wrote:
Oh, right. I never use a regexp that can match nothing, so I missed that. :-)
You never use '*'?
I guess he meant "match *only* nothing", most of the time using * you'll still use it in combination with a non-empty pattern. Easy to miss that only [something]* can match nothing and therefore first matches at the start of the line.
On 05/05/2016 03:35 AM, Ian Malone wrote:
On 5 May 2016 at 10:27, Patrick O'Callaghan pocallaghan@gmail.com wrote:
On Wed, 2016-05-04 at 16:24 -0700, Samuel Sieb wrote:
Oh, right. I never use a regexp that can match nothing, so I missed that. :-)
You never use '*'?
I guess he meant "match *only* nothing", most of the time using * you'll still use it in combination with a non-empty pattern. Easy to miss that only [something]* can match nothing and therefore first matches at the start of the line.
Yes, that's what I meant. I can't imagine where that would even be useful.
On Thu, May 05, 2016 at 08:56:51AM -0700, Samuel Sieb wrote:
On 05/05/2016 03:35 AM, Ian Malone wrote:
On 5 May 2016 at 10:27, Patrick O'Callaghan pocallaghan@gmail.com wrote:
On Wed, 2016-05-04 at 16:24 -0700, Samuel Sieb wrote:
Oh, right. I never use a regexp that can match nothing, so I missed that. :-)
You never use '*'?
I guess he meant "match *only* nothing", most of the time using * you'll still use it in combination with a non-empty pattern. Easy to miss that only [something]* can match nothing and therefore first matches at the start of the line.
Yes, that's what I meant. I can't imagine where that would even be useful.
Maybe not useful, but fun:
$ echo 123456789 | sed 's/Z*/|/g' |1|2|3|4|5|6|7|8|9|
On 05/05/2016 08:56 AM, Samuel Sieb wrote:
On 05/05/2016 03:35 AM, Ian Malone wrote:
On 5 May 2016 at 10:27, Patrick O'Callaghan pocallaghan@gmail.com wrote:
On Wed, 2016-05-04 at 16:24 -0700, Samuel Sieb wrote:
Oh, right. I never use a regexp that can match nothing, so I missed that. :-)
You never use '*'?
I guess he meant "match *only* nothing", most of the time using * you'll still use it in combination with a non-empty pattern. Easy to miss that only [something]* can match nothing and therefore first matches at the start of the line.
Yes, that's what I meant. I can't imagine where that would even be useful.
How about looking for "something[0-9]*" so it would match "something" or "something0" or "something99". "*" can be useful, you just have to be careful. ---------------------------------------------------------------------- - Rick Stevens, Systems Engineer, AllDigital ricks@alldigital.com - - AIM/Skype: therps2 ICQ: 226437340 Yahoo: origrps2 - - - - If you're not part of the solution, you're part of the precipitate - ----------------------------------------------------------------------
On 05/05/2016 10:11 AM, Rick Stevens wrote:
On 05/05/2016 08:56 AM, Samuel Sieb wrote:
On 05/05/2016 03:35 AM, Ian Malone wrote:
On 5 May 2016 at 10:27, Patrick O'Callaghan pocallaghan@gmail.com wrote:
On Wed, 2016-05-04 at 16:24 -0700, Samuel Sieb wrote:
Oh, right. I never use a regexp that can match nothing, so I missed that. :-)
You never use '*'?
I guess he meant "match *only* nothing", most of the time using * you'll still use it in combination with a non-empty pattern. Easy to miss that only [something]* can match nothing and therefore first matches at the start of the line.
Yes, that's what I meant. I can't imagine where that would even be useful.
How about looking for "something[0-9]*" so it would match "something" or "something0" or "something99". "*" can be useful, you just have to be careful.
See, it's such an odd thing to do that people don't understand it. :-) It's not about using *, I certainly do use that. It's about making a regexp that can match the empty string.
On Thu, 2016-05-05 at 10:31 -0700, Samuel Sieb wrote:
On 05/05/2016 10:11 AM, Rick Stevens wrote:
On 05/05/2016 08:56 AM, Samuel Sieb wrote:
On 05/05/2016 03:35 AM, Ian Malone wrote:
On 5 May 2016 at 10:27, Patrick O'Callaghan <pocallaghan@gmail. com> wrote:
On Wed, 2016-05-04 at 16:24 -0700, Samuel Sieb wrote:
Oh, right. I never use a regexp that can match nothing, so I missed that. :-)
You never use '*'?
I guess he meant "match *only* nothing", most of the time using
you'll still use it in combination with a non-empty pattern. Easy to miss that only [something]* can match nothing and therefore first matches at the start of the line.
Yes, that's what I meant. I can't imagine where that would even be useful.
How about looking for "something[0-9]*" so it would match "something" or "something0" or "something99". "*" can be useful, you just have to be careful.
See, it's such an odd thing to do that people don't understand it. :- ) It's not about using *, I certainly do use that. It's about making a regexp that can match the empty string.
I fail to see what's odd about it. When you match something with an optional part it's completely normal.
poc
On 05/05/2016 01:47 PM, Patrick O'Callaghan wrote:
On Thu, 2016-05-05 at 10:31 -0700, Samuel Sieb wrote:
On 05/05/2016 10:11 AM, Rick Stevens wrote:
On 05/05/2016 08:56 AM, Samuel Sieb wrote:
On 05/05/2016 03:35 AM, Ian Malone wrote:
On 5 May 2016 at 10:27, Patrick O'Callaghan <pocallaghan@gmail. com> wrote:
On Wed, 2016-05-04 at 16:24 -0700, Samuel Sieb wrote: > > Oh, right. I never use a regexp that can match nothing, so > I missed > that. :-) You never use '*'?
I guess he meant "match *only* nothing", most of the time using
you'll still use it in combination with a non-empty pattern. Easy to miss that only [something]* can match nothing and therefore first matches at the start of the line.
Yes, that's what I meant. I can't imagine where that would even be useful.
How about looking for "something[0-9]*" so it would match "something" or "something0" or "something99". "*" can be useful, you just have to be careful.
See, it's such an odd thing to do that people don't understand it. :- ) It's not about using *, I certainly do use that. It's about making a regexp that can match the empty string.
I fail to see what's odd about it. When you match something with an optional part it's completely normal.
Thank you for making my point once again... This is about the case where the entire regexp will match the empty string!
On Thu, 2016-05-05 at 13:56 -0700, Samuel Sieb wrote:
I fail to see what's odd about it. When you match something with an optional part it's completely normal.
Thank you for making my point once again... This is about the case where the entire regexp will match the empty string!
That was not what you appeared to say the first time (put it down to the ambiguity of English), but I'm glad we cleared it up and can stop going round in circles.
poc
Allegedly, on or about 05 May 2016, Samuel Sieb sent:
Yes, that's what I meant. I can't imagine where that would even be useful.
Matching nothing? Testing for a null response.