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.
when i do grep -i 'display*' abc.txt it is giving me output i.e 1st line
but when i do grep -i 'display+' abc.txt it gives nothing but it should give .i dont know why. please let me know if anyone knows. thanks in advance
Last edited by amanbijpuria; 01-13-2016 at 10:01 AM.
when i do grep -i 'display*' abc.txt it is giving me output i.e 1st line but when i do grep -i 'display*' abc.txt it gives nothing but it should give .i dont know why. please let me know if anyone knows. thanks in advance
Your post makes no sense...you posted the same command twice, saying the first time you run it it WORKS, then it DOESN'T...they both can't be true. Also, in the context you're using it, you don't need the wildcard, since grep will find the word display, regardless of what's before or after it.
first of all sorry for writing same code again ,i have corrected it.So instead of grep -i 'display*' abc.txt in 2nd line it will be grep -i 'display+' abc.txt .
In basic regular expressions the "+" character is not special, so you are looking for that character to appear literally in the line. To use its special meaning, you would have to preceed it with a backslash:
Code:
grep -i 'display\+' abc.txt
But again, why are you doing that? That looks for the string "displa" followed by one or more repetitions of the character "y". Just plain "display" would also match that.
Hi Rknicholes,
Thankyou for your reply .I have just given an example where my file data is like that. Now my question here grep -i 'display*' abc.txt is working without any backslash but in case of grep -i 'display\+' abc.txt i have to use backslash .why?
You need to pay closer attention. The asterisk will work in a basic regular expression for grep but the plus is considered an extended expression so you either need to escape it to let grep
know it is special or use the -E switch to use extended expressions.
As pointed out, neither seems really relevant, so your actual examples must need this as the current one it seems superfluous.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.