LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-15-2009, 09:49 AM   #1
casperdaghost
Member
 
Registered: Aug 2009
Posts: 349

Rep: Reputation: 16
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?
 
Old 08-15-2009, 09:57 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,991

Rep: Reputation: 2218Reputation: 2218Reputation: 2218Reputation: 2218Reputation: 2218Reputation: 2218Reputation: 2218Reputation: 2218Reputation: 2218Reputation: 2218Reputation: 2218
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.
 
Old 08-15-2009, 12:01 PM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Welcome to LQ!!

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

grep '\<cdu115\>' filename

This works in utilities other than grep.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
grep Regular Expression lamar_air Programming 2 07-24-2006 04:40 PM
Help with grep regular expression lamar_air Programming 3 07-21-2006 12:26 PM
Regular Expression + not Working with grep scottwmackey Linux - General 2 06-21-2006 02:31 AM
problems with regular expression and grep bwreath Linux - General 6 03-18-2005 02:43 PM
grep usage with regular expression jonathanztaub Linux - General 7 09-01-2004 11:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration