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.
All right, so here's an example:
grep -E "1{2}" file.txt (red means match)
111111111000
00011
11100
I expected 1{2} or 1\{2\} (whatever) to match only "1" only twice. In the first sentence, it seems to match 8 1s. The second should be correct, and the third, again, it's correct.
If I write:
grep -E "1{1}" file.txt, the third string (11100) shows up like this:
11100
So there are three 1s highlighted.
I don't really understand what's going on. It seems to work as the minium, as if I also wrote the comma after the number of occurences, instead of a fixed value.
I think the highlight is just a shell option (or a terminal option, maybe?). But I don't think it's something a real sysadmin should count on I'm just trying to profit from it, 'cause it's there.
I'm using the macos terminal and I'm connecting to a Centos 7.
The grep command has a "--color" option. If you have "grep" aliased to "grep --color=auto", then the matched characters will be colored when the output is going directly to a terminal. Using "--color=always" includes the color escape sequences even when the output is going to a file or is piped to another program. "--color=never" does what it implies, and is usually the default.
I think the highlight is just a shell option (or a terminal option, maybe?). But I don't think it's something a real sysadmin should count on I'm just trying to profit from it, 'cause it's there.
I'm using the macos terminal and I'm connecting to a Centos 7.
OIC
I am just in a normal everyday terminal. SO then this begs the question. If said person uses this type of code. He still got a see what they results are to be sure if he (or she) wrote it correctly. So getting an output that is the same as the input without anything to tell if it pick out the culprit one was looking for. It like putting identical twins in a line up wearing exactly the same thing, then having someone try to pick the one that did it.
The grep command has a "--color" option. If you have "grep" aliased to "grep --color=auto", then the matched characters will be colored when the output is going directly to a terminal. Using "--color=always" includes the color escape sequences even when the output is going to a file or is piped to another program. "--color=never" does what it implies, and is usually the default.
I must be needing --color=always then, as I know ls --color=auto is set.
so just do an alias for grep and set it to always, hum.. Now I got a go fiddle with that.
thanks
I must be needing --color=always then, as I know ls --color=auto is set.
so just do an alias for grep and set it to always, hum.. Now I got a go fiddle with that.
thanks
I strongly suggest that you do not set "--color=always" in an alias for "grep". That's going to cause gross problems if you try to use grep in a pipeline and forget that there are going to be ANSI escape sequences in the output. Using "--color=auto", like you probably have in your ls alias, should be fine.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.