Sunday, May 31, 2009

Regular expression examples

ls -a | grep '.[a-z]'
rm 'ls | grep '^[ab]$''
ls | grep '^[a-c]$'
ls -a | grep '^[a.]*$'


grep 'lin.x'*
grep -ls '^hosts' *
grep -ls 'hosts$' *


\< and \>
Search for patterns at the beginning of a word or at the end of a word. For instance, the following would show lines that have text beginning with san:

grep \< san *



\{n\} : The preceding character or regular expression occurs at least times. This is useful in a regular expression where you are looking for a number, say, between 100 and 999, as in the following command:

grep -ls '0-9\{3\}' *

No comments:

Post a Comment