top | item 25003367

(no title)

throwaway373438 | 5 years ago

Others have commented that many of these are general shell or terminal quoting problems.

Something that stood out for me is that the author did not mention ^V, which is very useful in quoting metacharacters. Take the tab example: The author seems to imply that PCRE is needed to match a tab because there is no \t escape sequence in BRE/ERE. Presumably he cannot just type in a tab because he's using a shell like bash, and tab has a special interpretation and cannot be typed in as a string literal.

The way around this is to use ^V as a terminal escape sequence, followed by simply pressing the tab key. This technique can be used to insert other control characters as string literals in arguments. Want to grep for EOF? "grep ^V^D" will get you there.

discuss

order

saurik|5 years ago

Or $'\t' can be used in bash to get some C-style escapes. (The ^V thing is epic though!)

eru|5 years ago

By the way, that technique also works in vim and some other editors, I think.

Jestar342|5 years ago

Yep. Allows for some seriously cool programmatic editing:

    g/^abc/norm ^3wciwHello^V^]2ei!
Any line starting with abc, replace the 3rd word with hello, and append an exclamation mark to the end of the 5th word. ^] is the control char for escape.