Re: a simple question about grep

2007-09-10 Thread Jerry
Thank you for all the great solutions!

Because of my extremely limited *nix knowledge, I'd use the approach of two
grep's in a pipeline, such as the one grep '^\*'  yourFile | grep -v
'^\*INDICATOR'  suggested by Michael, as it's simple to understand and easy
to memorize.

Thank you  again.

Zhao
___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/


Re: a simple question about grep

2007-09-07 Thread Tom Buskey
On 9/6/07, Kent Johnson [EMAIL PROTECTED] wrote:

 Tom Buskey wrote:
 
 
  On 9/6/07, *G.O.* [EMAIL PROTECTED] mailto:[EMAIL PROTECTED]
  wrote:
 
  egrep ^\*[^INDICATOR] filename.txt

 That excludes lines beginning with * and any of the characters INDCATOR,
 i.e. *N, *D, etc will all be excluded.

  That didn't work for me, but this did:
 
 egrep '^\*[^I][^N][^I][^D][^I][^C][^A][^T][^O][^R]' filename.txt

 That will exclude a line that matches INDICATOR at any character, for
 example *aN



You're right.

perhaps this:

 egrep -P ^\*(?!INDICATOR) filename.txt


GNU egrep  2.5.1 doesn't work:
$ cat z
*INDICATOR name1 zip1
geoid gender location
*INDICATOR name2 zip2
*geoid gender location
INDICATOR name3 zip3
*district court
$ egrep  '^\*(?!INDICATOR)' z
$

No output.
___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/


Re: a simple question about grep

2007-09-07 Thread Kent Johnson
Bill Ricker wrote:
   Or, if you only have an old grep, but do have Perl, the following should 
 work:
 
 The Andy and the ack project have built a better grep with perl.

Cool. By default ack ignores plain text files, so you have to tell it to 
include them even when explicitly specifying the file. Here is an ack 
command that solves the OP's problem:

ack --text '^\*(?!INDICATOR)' myfile.txt

Kent
___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/


Re: a simple question about grep

2007-09-07 Thread Ben Scott
On 9/7/07, Tom Buskey [EMAIL PROTECTED] wrote:
 egrep -P ^\*(?!INDICATOR) filename.txt

 GNU egrep  2.5.1 doesn't work:
 $ egrep  '^\*(?!INDICATOR)' z
 $

  You need to specify -P (or --perl) to turn on support for Perl
regular expression extensions.Otherwise it will interpret the (?
as... hmmm, to tell the truth, I'm not sure what that'll do.  I don't
think that's valid traditional regexp syntax.  In any event, it won't
work.

  Hmmm, for that matter, it doesn't seem to like egrep -P.  I guess
that's because egrep is basically just the same thing as grep -E,
and grep -E -P is invalid.  So try grep -P.  On a CentOS 5.0 box:

$ grep '^\*(?!INDICATOR)' sample
$ grep -P '^\*(?!INDICATOR)' sample
*geoid gender location
*district court
$ rpm -q grep
grep-2.5.1-54.2.el5
$

-- Ben
___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/


Re: a simple question about grep

2007-09-07 Thread Shawn K. O'Shea
Will if you're going to go into 3-letter tools that start with 'a'
that can do the requested task, then I'm just going to have to tell
everyone how to do it with awk

 awk '/^\*/  !/^\*INDICATOR/ { print $0 }' file

awk takes a pattern and then a set of things to do with lines that
match that pattern. So my pattern says line starts with '*' AND lines
does NOT start with '*INDICATOR'. Lines that match get processed by
the curly braces, which in this case prints out the entire line ($0 in
awk parlance)

-Shawn

On 9/7/07, Bill Ricker [EMAIL PROTECTED] wrote:
Or, if you only have an old grep, but do have Perl, the following should 
  work:

 The Andy and the ack project have built a better grep with perl.
 http://perladvent.pm.org/2006/5/
 search.cpan.org/~petdance/ack/ack
 petdance.com/ack/

 ack is pure Perl, so consistent across all platforms. Command name is
 25% shorter. :-) Heck, it's 50% shorter compared to grep -r. 
 use.perl.org/~petdance/journal/31763

 http://www.youtube.com/watch?v=G1ynTV_E-5s [Andy petdance giving
 ack Lighting talk at OSCON 2007, 9min]
 http://www.perlfoundation.org/perl5/index.cgi?ack

 Disclaimer - I have been known to contribute a patch to ack once in
 a blue moon.

 --
 Bill
 [EMAIL PROTECTED] [EMAIL PROTECTED]
 ___
 gnhlug-discuss mailing list
 gnhlug-discuss@mail.gnhlug.org
 http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/

___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/


Re: a simple question about grep

2007-09-06 Thread Michael ODonnell

grep '^\*'  yourFile | grep -v '^\*INDICATOR'

___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/


Re: a simple question about grep

2007-09-06 Thread Tom Buskey
egrep '^\*' FILE | egrep -v '^\*INDICATOR'

I'm not sure how you'd combine them into one REGXP.
I'm sure there's a better way in perl (GNU egrep will do perl with -P)

On 9/6/07, Jerry [EMAIL PROTECTED] wrote:

 Hi,

 I have a text file whose content looks like below:

 *INDICATOR name1 zip1
 geoid gender location
 *INDICATOR name2 zip2
 *geoid gender location
 INDICATOR name3 zip3
 *district court

 I want to pick up all lines starting with * but no INDICATOR
 followed.

 So for the example above, I want to pick up the following 2 lines:

 (the 3rd line) *geoid gender location
 (the last line) *district court

 How to construct regular expression with grep as a one-line command to
 achieve this goal? Or any other simple solutions?
 Thank you!

 Zhao

 ___
 gnhlug-discuss mailing list
 gnhlug-discuss@mail.gnhlug.org
 http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/


___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/


Re: a simple question about grep

2007-09-06 Thread Star
 I want to pick up all lines starting with * but no INDICATOR
 followed.

I'd double-grep it, but i'm not infront of a *nix box to check

grep -i * | grep -v *INDICATOR filename

or something to that effect.

-- 
~ *
___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/


Re: a simple question about grep

2007-09-06 Thread G.O.
egrep ^\*[^INDICATOR] filename.txt

gurhan

On 9/6/07, Jerry [EMAIL PROTECTED] wrote:
 Hi,


 I have a text file whose content looks like below:


 *INDICATOR name1 zip1
 geoid gender location
  *INDICATOR name2 zip2
  *geoid gender location
  INDICATOR name3 zip3
  *district court


 I want to pick up all lines starting with * but no INDICATOR
  followed.


 So for the example above, I want to pick up the following 2 lines:


 (the 3rd line) *geoid gender location
  (the last line) *district court


 How to construct regular expression with grep as a one-line command to
 achieve this goal? Or any other simple solutions?
  Thank you!

 Zhao

 ___
 gnhlug-discuss mailing list
 gnhlug-discuss@mail.gnhlug.org
 http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/


___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/


Re: a simple question about grep

2007-09-06 Thread Tom Buskey
On 9/6/07, G.O. [EMAIL PROTECTED] wrote:

 egrep ^\*[^INDICATOR] filename.txt

 gurhan


That didn't work for me, but this did:

   egrep '^\*[^I][^N][^I][^D][^I][^C][^A][^T][^O][^R]' filename.txt



On 9/6/07, Jerry [EMAIL PROTECTED] wrote:
  Hi,
 
 
  I have a text file whose content looks like below:
 
 
  *INDICATOR name1 zip1
  geoid gender location
   *INDICATOR name2 zip2
   *geoid gender location
   INDICATOR name3 zip3
   *district court
 
 
  I want to pick up all lines starting with * but no INDICATOR
   followed.
 
 
  So for the example above, I want to pick up the following 2 lines:
 
 
  (the 3rd line) *geoid gender location
   (the last line) *district court
 
 
  How to construct regular expression with grep as a one-line command to
  achieve this goal? Or any other simple solutions?
   Thank you!
 
  Zhao
 
  ___
  gnhlug-discuss mailing list
  gnhlug-discuss@mail.gnhlug.org
  http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/
 
 
 ___
 gnhlug-discuss mailing list
 gnhlug-discuss@mail.gnhlug.org
 http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/

___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/


Re: a simple question about grep

2007-09-06 Thread Kent Johnson
Tom Buskey wrote:
 
 
 On 9/6/07, *G.O.* [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] 
 wrote:
 
 egrep ^\*[^INDICATOR] filename.txt

That excludes lines beginning with * and any of the characters INDCATOR, 
i.e. *N, *D, etc will all be excluded.

 That didn't work for me, but this did:
 
egrep '^\*[^I][^N][^I][^D][^I][^C][^A][^T][^O][^R]' filename.txt

That will exclude a line that matches INDICATOR at any character, for 
example *aN

perhaps this:

egrep -P ^\*(?!INDICATOR) filename.txt

Kent
___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/


Re: a simple question about grep

2007-09-06 Thread Ben Scott
On 9/6/07, Kent Johnson [EMAIL PROTECTED] wrote:
 perhaps this:

 egrep -P ^\*(?!INDICATOR) filename.txt

  Assuming your grep supports the Perl regular expression extensions
(a useful thing to have), that should work.

  Or, if you only have an old grep, but do have Perl, the following should work:

perl -pe '/^\*(?!INDICATOR)/ and print' filename.txt

  Otherwise, I agree with what other suggested, using two grep's in a pipeline.

-- Ben
___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/


Re: a simple question about grep

2007-09-06 Thread Bill Ricker
   Or, if you only have an old grep, but do have Perl, the following should 
 work:

The Andy and the ack project have built a better grep with perl.
http://perladvent.pm.org/2006/5/
search.cpan.org/~petdance/ack/ack
petdance.com/ack/

ack is pure Perl, so consistent across all platforms. Command name is
25% shorter. :-) Heck, it's 50% shorter compared to grep -r. 
use.perl.org/~petdance/journal/31763

http://www.youtube.com/watch?v=G1ynTV_E-5s [Andy petdance giving
ack Lighting talk at OSCON 2007, 9min]
http://www.perlfoundation.org/perl5/index.cgi?ack

Disclaimer - I have been known to contribute a patch to ack once in
a blue moon.

-- 
Bill
[EMAIL PROTECTED] [EMAIL PROTECTED]
___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/