LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   grep regular expression (https://www.linuxquestions.org/questions/linux-newbie-8/grep-regular-expression-747751/)

casperdaghost 08-15-2009 08:49 AM

grep regular expression
 
i work in finance.

i was looking through a 80 meg file to verify if accounts are attached to a process. some processes can have up to 10,000 accounts attached to them, some can have just one.

i tried this :

grep cdu115 ~/data/flat_files/account.t

and came up with thousands of accounts attached to processes cdu115a, cdu115c, cdu115f, and so on- but what i was looking for was just plain old cdu115. even if just one account is attached to this process, it is valid.

so i tired this

egrep '^cdu115$' ~/data/flat_files/account.t - which resulted in nothing, so the process is invalid. but just to be sure i tried:


egrep '^cdu115a$' ~/data/flat_files/account.t - which also resulted in nothing - but is false because when i greped cdu115 from this file i saw thousands of entries for cdu115a.

so i am uncertain.

I tried grep -e, double quotes, encasing the regex in / ... / .

i need to be certain that there are no accounts attached to process cdu115 before i delete it. and that is cdu115 without extremeties - no cdu115a, cdu115b, cdu115c, cdu115d, ect.

how can i be certain in regex terms that i am looking for just cdu115 and not cdu115a, cdu115b, cdu115c, ect.

what is the proper regex for this situation?

syg00 08-15-2009 08:57 AM

You need to read the manpage (better) to see how to limit the match to "boundaries". Several ways to do it with grep - easiest in your case is probably to use the "-w" switch.

pixellany 08-15-2009 11:01 AM

Welcome to LQ!!

There's also the "word boundary" regex....eg:

grep '\<cdu115\>' filename

This works in utilities other than grep.


All times are GMT -5. The time now is 03:24 AM.