Unix syntax for the grep command for only an ending character -


for file james, when run command:

cat james | grep ["."] 

i lines contain dot.

how lines end dot?

to find lines end . character:

grep '\.$' james 

your cat command unnecessary; grep able read file itself, , doesn't need cat job it.

a . character special in regular expressions, matching 1 character; need escape \ match literal . character.

and need enclose whole regular expression in single quotes because \ , $ characters special shell. in regular expression, $ matches end of line. (you're dealing characters treated specially shell, , others treated specially grep; single quotes shell out of way can control grep sees.)

as square brackets used in question, that's way escape ., it's unusual. in regular expression, [abc] matches single character that's of a, b, or c. [.] matches single literal . character, since . loses special meaning inside square brackets. double quotes used: ["."] unnecessary, since . isn't shell metacharacter -- square brackets are special shell, similar meaning meaning in regular expression. your

grep ["."] 

is equivalent to

grep [.] 

the shell expand [.] list of every visible file name contains single character .. there's such file, namely current directory . -- shell's [] expansion ignores files names start .. since there's nothing expand [.] to, it's left alone, , grep sees [.] argument, just happens work, matching lines contain literal . character. (using different shell, or same shell different settings, mess up.)

note shell doesn't (except in limited contexts) deal regular expressions; rather uses file matching patterns, less powerful.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -