Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
echo "The fox jumped over 3 fences" | grep '[0-9]'
The fox jumped over 3 fences
But , using the regex \d produce a different result
echo "The fox jumped over 3 fences" | grep '\d'
The fox jumped over 3 fences
Why do these types of regex \d \w \s \w do not work with grep or am I using it wrong. Does sed and awk understand those regex types above? Thank you in advance!
Dave Morris has done some podcasts about awk and sed at Hacker Public Radio; the shownotes are extremely detailed. They might be a help, as regex is integral to expertise in sed and awk.
(If I ever understand regex, I will feel entitled to call myself a "Linux geek" instead of a "Linux guy.")
glad to help you
if you really want to say thanks just click on yes
Quote:
Originally Posted by MBoyle19
I thought you had to use quotes if a variable had spaces.
And this is the case when you do not need (but in general yes, you have to use quotes).
Quote:
Can sed and awk understand shorthand regex?
grep knows 3 different kind of regex, sed knows at least 2, awk has its own style, but more or less similar....
perl has its own PCRE and python knows that too.
I didn't know the exact name they were called. So I called it regex types. Tobyv did mentioned above it was called short hand regex.
Can sed and awk understand shorthand regex?
syg00 mentioned them above in #2 and #4. They are perl regular expressions, ported to other languages this is often called perl-compatible regular expression (PCRE). Within perl they are properly called metasymbols and they stand in for some functionality as well as pattern data. You'll find PCRE nearly everywhere these days.
But as to whether sed and awk can understand perl's regular expression metasymbols, the answer is, "no" at least for existing versions to-date.
If you find them useful, then you can get a lot out of one-liners in perl. See the options -e, -i, -n, and -p in
Code:
man perlrun
Anything you can do with sed and awk you can do, plus more, in perl.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.