How to use regular expression (regex) in grep or vi?  

Wednesday, July 8, 2009

How to use regular expression (regex) in grep or vi?

If you need to search for a pattern of "string" or "character" in a file / many files, you will need to use regular expression (regex) either in vi editor or in grep command. But how? See below:

using vi:
- press '/' for searching
- for instance, i wanted to search for CL000, CL001, CL002, ie: the pattern is CLXXX follow by digit.
- syntax:
/^CL[0-9]*

^ - start of pattern
* - zero or more digit

using unix grep command:
- grep CL[0-9]

AddThis Social Bookmark Button
Email this post


Design by Amanda @ Blogger Buster