Regular expression with egrep and ls
October 7th, 2006 mysurface Posted in egrep, grep, ls, Regular Expression, Symbol, Text Manipulation | Hits: 65407 | 2 Comments »
egrep is actually same as grep -E, it interpret PATTERN as an extended regular expression. Therefore ESCAPE ( \ ) is not needed for certain symbol.
ls is a common tool for listing file that matches the keyword.
Regular expression (RE) is a very important and useful to manipulating strings and text. In this example, I would like to introduce few RE symbols.
Asterisk ( * ) – This matches any number (including ZERO) of repeats of the character string.
ls "file1234*"
This will return files with filename: file123, file1234, file 1223444.
Dot ( . ) – This will matches any one character, but except newline.
ls "file1234."
This will return files with filename: file1234q, file12345, but not file1234
Caret ( ^ ) – This indicate begin of line, but sometimes it indicate negative too.
Dollar Sign ( $ ) – This indicate end of line, but sometimes it indicate value of variable too.
If you want to grep “void” at the begin of lines, you do this:
egrep "^void" myhello.c
If you want to grep “)” at the end of lines, you do this:
egrep "\)" myhello.c
You need to put escape because “)” is a special symbol.
To filter out the blank lines, you do this:
grep -v "^$" mysetting.conf







October 17th, 2006 at 12:57 pm
[...] Previously we have an example on regular expression, but It doesn’t shows the power of square brackets ( [ ] ) [...]
May 4th, 2010 at 1:59 pm
little helpful… but what about *,+ and ?
where are they ?