![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 ? |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
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 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 "$"
Tayyab |
|
#3
|
||||
|
||||
|
grep -v -i "^[^.]*\.aaa\.bbb\.ccc,[^,]*,[^,][^,],infrastructure,fast,__NONE__,__NONE__"
|
||||
| Google The UNIX and Linux Forums |
| Tags |
| regex, regular expressions |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|