![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| UNIX newbie NEWBIE question! | Hanamachi | UNIX for Dummies Questions & Answers | 4 | 03-28-2009 04:10 PM |
| Newbie needs help with simple script | shizizzle | Shell Programming and Scripting | 12 | 03-21-2006 12:01 PM |
| Ok simple question for simple knowledge... | Corrail | UNIX for Dummies Questions & Answers | 1 | 11-28-2005 01:03 PM |
| Simple grep question, but I'm out of practice | citygov | Shell Programming and Scripting | 0 | 08-02-2005 10:31 AM |
| simple grep question | UNIX for Dummies Questions & Answers | 5 | 01-27-2003 11:00 PM | |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Simple newbie grep question
How come grep [sd] testfile1 won't find anything in testfile1 (even though the characters sd are there in great quantity), but grep '[sd]' testfile1 will find plenty?
Do the single quotes prevent the shell from interpreting the [ test command? So when not using single quotes, the grep [sd] testfile1 is interpreted as: grep *test whether or not characters sd exist* testfile1? Or is the explanation much simpler? Thanks! |
|
||||
|
Thank you!
Second question: Is there way to insert math into a grep, for example: In a large chat log file I want to grep for every instance of an abbreviation of an ordinal number: 21st, 31st, 41st, 101st, 401st, 2nd, 22nd, 32nd etc. So I would want to do egrep [x+10]st|y+10]nd|[z+10]rd] chatlog.txt or something like that. Is there any way to have the shell evaluate this math and append 'st' 'nd' 'rd' as necessary? Thanks! Last edited by doubleminus; 04-05-2008 at 04:11 PM.. |
|
||||
|
Read up on regular expressions. The egrep manual page has a very brief summary; some systems also have a regex(5) manual page which is a bit more detailed. Any good Unix beginners book will have a chapter or five on the subject.
There's absolutely no math in there but it's a very powerful and versatile facility for matching ... stuff. Code:
egrep '1st|2nd|3rd|[4-9]th' chatlog.txt |
![]() |
| Bookmarks |
| Tags |
| regex, regular expressions |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|