|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Exclude dash in grep
Hi, I must be overlooking something, but I don't understand why this doesn't work. I'm trying to grep on a date, excluding all the lines starting with a dash: testfile: Code:
#2013-12-31 2013-12-31 code: Code:
grep '^[^#]2013-12-31' testfile I'm expecting to see just the second line '2013-12-31' but I don't get any results. grep -v is not an option btw. |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
[^#] means a single character that is not a hash-sign. Why not use: Code:
grep '^2013-12-31' But perhaps you mean this: Code:
grep '^[^#]*2013-12-31' |
| The Following User Says Thank You to Scrutinizer For This Useful Post: | ||
Subbeh (01-21-2013) | ||
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
Elementary.
[^#] will match one character which is not an octothorpe (or hash). So, what you are asking
grep to match is one non-hash character (mandatory for the overall pattern to match) at the beginning of a line followed by
2013-12-31 .
Get it? |
| The Following User Says Thank You to elixir_sinari For This Useful Post: | ||
Subbeh (01-21-2013) | ||
|
#4
|
|||
|
|||
|
Quote:
Code:
grep '^[^#]*2013-12-31' seems to work by the way. Thanks
|
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Grep for a srting & exclude two folders | mohtashims | Shell Programming and Scripting | 1 | 12-07-2012 10:13 AM |
| Exclude dash (-) from word separators in vi | cabhi | UNIX for Advanced & Expert Users | 3 | 03-22-2012 12:57 AM |
| Using Grep Include/Exclude Files | metallica1973 | Shell Programming and Scripting | 8 | 10-28-2011 01:08 AM |
| how to exclude the GREP command from GREP | yamsin789 | UNIX for Advanced & Expert Users | 2 | 10-05-2007 02:59 AM |
| grep - to exclude lines beginning with pattern | frustrated1 | Shell Programming and Scripting | 2 | 08-29-2005 07:18 AM |
|
|