Timeline for How to highlight the matched regex pattern got by many regex exps disjoined with `||` in awk?
Current License: CC BY-SA 4.0
15 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Dec 31, 2024 at 1:58 | comment | added | An5Drama | Let us continue this discussion in chat. | |
| Dec 30, 2024 at 9:52 | comment | added | Stéphane Chazelas |
@An5Drama, no you've got it backward, (?!...) (not !? which without the (...) just matches 0 or 1 !) looks ahead, it doesn't consume. It correctly matches on the first foo because it's not followed by ` bar` and correctly does not match on the second because it is followed by ` bar` . Thanks to the fact it does not consume input, it would correctly match on the first two occurrences of foo in the output of echo foo foo foo bar.
|
|
| Dec 30, 2024 at 8:23 | comment | added | An5Drama |
Thanks. With that printf demo, I also found that ?! seems to consume checked string, so 'foo(?! bar)' won't filter out "foo foo bar". This seems to be implied implicitly by python re doc stackoverflow.com/a/11430936/21294350 and also in man perlre "the lookaheads are zero-width expressions--they only look, but don't consume any of the string".
|
|
| Dec 30, 2024 at 7:00 | comment | added | Stéphane Chazelas |
@An5Drama see edit. To see the differences between the various commands, you can check on the output of printf '%s\n' foo 'foo bar' 'foo foo bar' 'bar foo' bar as it's not clear in your question whether you want to just highlight some foos or also discard the lines without foo or with foo bar (and whether or not they also contain foo not followed by ` bar`).
|
|
| Dec 30, 2024 at 6:55 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 |
added 398 characters in body
|
| Dec 30, 2024 at 2:57 | comment | added | An5Drama |
Some references for the edit: 1. $'...': unix.stackexchange.com/q/371827/568529. 2. ast-open's sed: github.com/att/ast/blob/master/lib/package/ast-open.README 3. < used at the beginning of line: superuser.com/a/843143/1658455 where < influences the command before control operator |
|
|
| Dec 30, 2024 at 2:54 | comment | added | An5Drama |
which is also said by your last paragraph. Similarly sed -n doesn't print by default as perl -n and we use p modifier, so still same (Similar for the rest). Is it that case?
|
|
| Dec 30, 2024 at 2:53 | comment | added | An5Drama |
Thanks so much for the so detailed edit. Small questions: 1. Is -e '^' in grep --color -e '^' -e foo necessary? IMHO that just grep those lines with the beginning "empty string" and different -es doesn't influence with each other as man says. 2. IMHO "To discard all the lines that contain foo bar and all that don't contain foo and highlight foo in the remaining ones:" is same as "To discard the lines that contain foo bar and highlight occurrences of foo in remaining lines," since if ! a && b is same as unless a{b} based on short circuit of && for perl (Continued)
|
|
| Dec 29, 2024 at 16:49 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 |
added 2212 characters in body
|
| Dec 29, 2024 at 16:42 | comment | added | Stéphane Chazelas | @An5Drama, see edit. | |
| Dec 29, 2024 at 16:41 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 |
added 2212 characters in body
|
| Dec 29, 2024 at 13:36 | comment | added | An5Drama |
The perl doc is really large and I haven't learnt about that language before. One small question: Is there one way to avoid outputting the lines like foo bar?
|
|
| Dec 29, 2024 at 13:34 | comment | added | An5Drama |
Some references for someone unfamiliar with perl same as me: 1. -p learnbyexample.github.io/learn_perl_oneliners/… seems to ensure outputting the results "$_ is automatically printed". 2. options like -e: see man perlrun 3. $&: man perlretut 4. unless: man perlsyn
|
|
| Dec 29, 2024 at 11:24 | comment | added | An5Drama |
Thanks anyway although normally I don't use perl.
|
|
| Dec 29, 2024 at 9:39 | history | answered | Stéphane Chazelas | CC BY-SA 4.0 |