The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
regular expressions whatever Shell Programming and Scripting 4 05-20-2007 01:30 PM
Regular Expressions sandeep_hi Shell Programming and Scripting 6 06-11-2006 11:12 PM
More Grep - Regular Expressions Jombee UNIX for Dummies Questions & Answers 7 09-05-2005 09:55 AM
Regular Expressions AresMedia Shell Programming and Scripting 1 08-22-2002 12:55 PM
Regular expressions in sed mfreemantle UNIX for Dummies Questions & Answers 3 02-11-2002 06:34 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 08-14-2006
Registered User
 

Join Date: Nov 2005
Location: Canada
Posts: 30
grep and regular expressions :

I wrote a simple korn shell where I am trying to filter all the good record layouts of a file to only leave the bad ones to look at. That file is hudge. Aside from '# comments' and 'var=ssss', all record should follow a specific record layout, with comma seperated fields. Some fields can have any value, others a choice of 4-5 different values.

First I tried running the script but noticed at the end that some grep didn't filter out some cases. So I tried them one by one until i got to the grep4 creation. It doesn't filter out the case it looks for.

grep -v -i '^#' filea.txt >grep1.tmp
grep -v -i "=" grep1.tmp >grep2.tmp
grep -v -i "^*.aaa.bbb.ccc,*,??,infrastructure,slow,__NONE__,__NONE__" grep2.tmp >grep3.tmp
grep -v -i "^*.aaa.bbb.ccc,*,??,infrastructure,fast,__NONE__,__NONE__" grep3.tmp >grep4.tmp
grep -v -i "^*.aaa.bbb.ccc,*,??,infrastructure,hybrid,__NONE__,__NONE__" grep4.tmp >grep5.tmp
grep -v -i "^*.aaa.bbb.ccc,*,??,??,fast,__NONE__,__NONE__" grep5.tmp >grep6.tmp
grep -v -i "^*.aaa.bbb.ccc,*,??,??,slow,__NONE__,__NONE__" grep6.tmp >grep7.tmp
grep -v -i "^*.aaa.bbb.ccc,*,??,??,hybrid,__NONE__,__NONE__" grep7.tmp >grep8.tmp
cat grep8.tmp | more
rm grep?.tmp



grep3.tmp file
...
usbisbb007zfs36.aaa.bbb.ccc,uslastm007zfsx6-zfs-gaw,us,infrastructure,fast,__NONE__,__NONE__
uslaqlr007zfs36.aaa.bbb.ccc,uslastm007zfsx6-zfs-gaw,us,infrastructure,fast,__NONE__,__NONE__
uslaqlr017zfs36.aaa.bbb.ccc,uslastm007zfsx6-zfs-gaw,us,infrastructure,fast,__NONE__,__NONE__
ussvsbb017zfs36.aaa.bbb.ccc,uslastm007zfsx6-zfs-gaw,us,infrastructure,fast,__NONE__,__NONE__

>grep -v -i "^*.aaa.bbb.ccc,*,??,infrastructure,fast,__NONE__,__NONE__" grep3.tmp | more
uslastm007zfsx6.aaa.bbb.ccc,uslastm007zfsx6-zfs-gaw,us,infrastructure,fast,__NONE__,__NONE__
uslasmn007zfsx6.aaa.bbb.ccc,uslastm007zfsx6-zfs-gaw,us,infrastructure,fast,__NONE__,__NONE__
uslassh007zfs36.aaa.bbb.ccc,uslastm007zfsx6-zfs-gaw,us,infrastructure,fast,__NONE__,__NONE__
...

Are some of my grep characters special reserved ones ?
Why doesn't it work ?
Reply With Quote
Forum Sponsor
  #2  
Old 08-14-2006
tayyabq8's Avatar
Moderator
 

Join Date: Nov 2004
Location: Bahrain
Posts: 555
You miss quite basic concepts of regex, try to browse thru these forums and FAQs and learn regex, for your current problem, try something like this:
Code:
grep -v -i "^[^\.]*\.aaa\.bbb\.ccc,[^,]*,us,infrastructure,fast,__NONE__,__NONE__$" grep3.tmp
Explanation of above code:
Code:
^[^\.]*\.       Parse from the begining of the line until it finds first "." dot.
\.              A "\" is being used here to escape dot's sepcieal feature in regex.
aaa\.bbb\.ccc,  Search for aaa.bbb.ccc,
[^,]*,          Parse until it finds next "," comma
                And rest is simple string until end of line "$"
Regards,
Tayyab
Reply With Quote
  #3  
Old 08-14-2006
Hitori's Avatar
Registered User
 

Join Date: Jun 2006
Posts: 360
grep -v -i "^[^.]*\.aaa\.bbb\.ccc,[^,]*,[^,][^,],infrastructure,fast,__NONE__,__NONE__"
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
regex, regular expressions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 03:27 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0