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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,513
Rep:
Anything in square brackets means list or range. [0-9] means any single integer 0 thru 9 inclusive. [12345] means any combination of one or more in the list. I think the "\+" might produce no output. But this exercise is so mundane I can only hope it's a class assignment and not actual on-the-job stuff.
You might want to change the quotes from double to single.
Last edited by AwesomeMachine; 08-23-2017 at 05:52 AM.
\+ is one of these questionable BRE extensions in Linux.
Clear and portable is \{1,\} or + in egrep (or grep -E that uses ERE).
It means the preceding character(-wildcard) must exist 1 or more times.
\+ is one of these questionable BRE extensions in Linux.
Clear and portable is \{1,\} or + in egrep (or grep -E that uses ERE).
It means the preceding character(-wildcard) must exist 1 or more times.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,194
Rep:
Quote:
Originally Posted by MadeInGermany
\+ is one of these questionable BRE extensions in Linux.
Clear and portable is \{1,\} or + in egrep (or grep -E that uses ERE).
It means the preceding character(-wildcard) must exist 1 or more times.
I knew that as well [0-9]+ matches one or more [0-9]. Just like an '*' matches zero or more.
But why the '\' in front of \+? That would indicate a literal '+', wouldn't it?
I use [0-9]+ and [0-9]{3} quite often, but I was looking forward to an answer to [0-9]\+
In ERE (extended regular expression) the special meaning is {m,n} and +
In BRE (basic regular expression) the special meaning is \{m,n\}
Someone thought it makes sense to have \+ in BRE following the same logic. This is in newer Linux only; it is not in the standards.
Also some take-overs from PRE (Perl regular expression, highly compatible with ERE) went into newer Linux BRE and ERE, like \b \s \d I wouldn't use them: no standard, not portable.
Instead use
\< \> (left and right word boundary, quite portable in BRE but also no standard)
[[:space:]]
[0-9] or [[:digit:]]
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,194
Rep:
I knew there were some differences in syntax between BRE and ERE. I always thought ERE was an extension of BRE and upward compatible. Not so. That backslashes have an opposite effect in some situations in BRE and ERE I never knew. Never too old to learn.
I knew there were some differences in syntax between BRE and ERE. I always thought ERE was an extension of BRE and upward compatible. Not so. That backslashes have an opposite effect in some situations in BRE and ERE I never knew. Never too old to learn.
jlinkels
Not so. Yes, you are right. And it is valid not only for grep, but for sed too.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.