Grep regex: bracket
Code:
#First grep result using regex '[c]ron', quotes not included. Quote:
|
I admit I looked this one up https://unix.stackexchange.com/quest...rom-ps-results :)
|
Quote:
Thanks. I still do not get it. Can you elaborate very sloooowly? |
You get different results because one is a pattern and the other is a string.
Both instances of grep are looking for a regex pattern among strings produces by ps. Since that string is present in the lines for PID 877 and 26692, they will both be printed. Code:
root 877 1 0 Mar04 ? 00:00:00 /usr/sbin/cron -f Code:
user1 26693 11882 0 18:03 pts/2 00:00:00 grep --color=auto [c]ron However, if you were to try [\]]ron or [[:punct:]]ron, you'd find 26693. But note carefully what the colors show as the matched pattern. If you want the whole [c]ron thing you'd need a broader pattern like [c[:punct:]]ron to find it. tldr; you've made a pattern that does not match itself by using a set |
Quote:
Here is how I understood what you said. When we do this: Code:
~ $ ps -ef | grep "[[:punct:]]ron" It prints out (as one of its many lines for all the processes) the grep process and its arguments. Code:
user1 9197 8355 0 22:45 pts/1 00:00:00 grep --color=auto [[:punct:]]ron Likewise when we do this (as you have mentioned): Code:
~ $ ps -ef | grep "[c]ron" were piped into grep, and they are: Code:
... ... However regex "[c]ron", quotes excluded, only match string pattern "cron". And there is no "cron" string in ps output string below: Code:
user1 9197 8355 0 22:45 pts/1 00:00:00 grep --color=auto [c]ron You wrote this: Code:
However, if you were to try [\]]ron or [[: punct :]]ron, you'd find 26693. But note carefully what the colors show as the matched pattern. If you want the whole [c]ron thing you'd need a broader pattern like [c[: punct :]]ron to find it. Code:
~ $ ps -ef | grep "[]\]ron" Thank you. |
Quote:
There are two ways to avoid the smilies. One is to put an emtpy tag pair inbetween them. :[b][/b]P But that's not efficient. Another way is to look in the section under the text box, below the Submit Reply button in the "Additional Options" menu. There is a heading "Miscellaneous Options" with a check box for "Disable smilies in text" |
Thank you Turbocapitalist!
|
All times are GMT -5. The time now is 04:29 AM. |