PDA

View Full Version : regular expressions with grep


Swab
January 1st, 2006, 06:47 PM
I want to search for any occurance of 45104 following any tabs or spaces... I'm new to regular expressions and don't understand why the following is not working.

egrep '\t+45104' input.txt

Any pointers?

toojays
January 1st, 2006, 09:27 PM
I just had a try of this myself, and it seems like the tab escape isn't being interpreted properly for some reason. For me, it worked when I used a literal tab instead of a '\t'. You can type a literal tab in the shell by pressing Control-V and then hitting TAB.

To do what you really want, you need:

egrep '[<literal-tab><literal space>]+45104' input.txt

so that it can be tabs OR spaces in front of the number.

Swab
January 1st, 2006, 09:43 PM
That worked! Thanks for the help, much appreciated!