grep or keep my mind sane

Uncategorized — Антон Марчуков @ 06.02.06 23:19

We are given two examples:

antonm@antares:~$ echo “Setting the mixer vol from 60:60 to 61:61.” | grep -o “to [0-9]+” | grep -o “[0-9]+”
antonm@antares:~$

antonm@antares:~$ echo “Setting the mixer vol from 60:60 to 61:61.” | grep -oE “to [0-9]{1,}” | grep -o -E “[0-9]{1,}”
61
antonm@antares:~$

But, why isn’t the first one working? I guess neither -o nor -E option affect pipes, instead, those examples treat a string different. Maybe home/end of line (^/$) issues? Don’t know yet, but this seems to be very interesting when known.

Update: this one also doesn’t work:

antonm@antares:~$ echo “Setting the mixer vol from 60:60 to 61:61.” | grep -o “to [0-9]+”
antonm@antares:~$

but, it does for extended grep (given -E option), uhh, that seems to be the problem.


No comments yet.

Leave a comment


This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
(c) 2017 Anton Martchukov's Weblog | powered by WordPress with Barecity