Timeline for How do I extract the digits from a line and save it into a variable?
Current License: CC BY-SA 4.0
16 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jun 12, 2021 at 22:53 | comment | added | Daniel Kaplan | @roaima true, admittedly, I didn't want to post every failed attempt I made 1) because I found something that kind of worked but felt clunky, 2) somehow i got it in my head that sed's s/... can't use */+ (I must have misunderstood a SO answer for one of the parts I was researching before I posted this). In my head that misinterpretation was an invariant. At that point, bringing that detail up seemed irrelevant, like bringing up which hand I used for the mouse as I tried to get this to work. TL;DR: When you assume, you make an... | |
| Jun 12, 2021 at 11:52 | history | rollback | cas | Rollback to Revision 3 | |
| Jun 12, 2021 at 9:17 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 | added 2 characters in body |
| Jun 12, 2021 at 8:34 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 | added 257 characters in body |
| Jun 12, 2021 at 7:45 | comment | added | Kusalananda♦ | Ok, good, but I was mostly thinking about the PCRE-like expression available even if -P isn't used. | |
| Jun 12, 2021 at 7:43 | comment | added | cas | @Kusalananda GNU grep -P uses libpcre and not some GNU implementation of it, so I expect it will behave identically to anything else using PCRE. Whether that's identical to perl's behaviour, I don't know. perl has good unicode support. man pcre says The current implementation of PCRE corresponds approximately with Perl 5.12, including support for UTF-8/16/32 encoded strings and Unicode general category properties. However, UTF-8/16/32 and Unicode support has to be explicitly enabled; it is not the default. The Unicode tables correspond to Unicode release 6.3.0. | |
| Jun 12, 2021 at 7:38 | comment | added | Kusalananda♦ | @cas Is \d and \s and the other PCRE-like shortcuts adopted by GNU identical to PCRE when used in GNU regular expressions? Do they behave the same in various locales as Perl REs would, for example? | |
| Jun 12, 2021 at 7:08 | history | edited | cas | CC BY-SA 4.0 | added 3 characters in body |
| Jun 12, 2021 at 7:03 | comment | added | Chris Davies | @DanielKaplan there was no mention of that anywhere in your question | |
| Jun 12, 2021 at 7:01 | comment | added | cas | I'm kind of surprised that GNU sed doesn't do \d yet. It's not like they haven't copied other RE niceties from perl, like \s. and \d has advantages over [0-9] (valid digits aren't limited to just [0-9], depending on language). OTOH, [0-9.+-]+ is arguably easier than (?:\d|[.+-])+. | |
| Jun 12, 2021 at 6:51 | vote | accept | Daniel Kaplan | ||
| Jun 12, 2021 at 6:51 | comment | added | Daniel Kaplan | okay that explains the only problem I was having the whole time. Thanks! | |
| Jun 12, 2021 at 6:50 | comment | added | cas | unfortunately, no. perl does, though :). perl -lne 'print if s/^\s*foo\s*=\s*(\d+).*/$1/' file | |
| Jun 12, 2021 at 6:50 | comment | added | Daniel Kaplan | wait so does sed not have \d? | |
| Jun 12, 2021 at 6:50 | history | edited | cas | CC BY-SA 4.0 | dealing with whitespace |
| Jun 12, 2021 at 6:43 | history | answered | cas | CC BY-SA 4.0 |