How to write GREP command in UNIX

How to write GREP command in UNIX

Post by Maan » Tue, 30 Nov 1999 04:00:00



Hello everybody ,
I am a student in KFUPM
I have a project about how t write and implement the source
codes of GREP function in the shell of UNIX

Please , if you have any idea about that topic , send your

and I will be very thankful .

* Sent from AltaVista http://www.altavista.com Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping.  Smart is Beautiful

 
 
 

How to write GREP command in UNIX

Post by Peter Sundstro » Wed, 01 Dec 1999 04:00:00



Quote:> Hello everybody ,
> I am a student in KFUPM
> I have a project about how t write and implement the source
> codes of GREP function in the shell of UNIX

I think the operative word in your post is "I", ie: YOU have a project which
YOU should write.

 
 
 

How to write GREP command in UNIX

Post by Ken Pizzi » Wed, 01 Dec 1999 04:00:00


On Mon, 29 Nov 1999 03:30:04 -0800,


>I am a student in KFUPM
>I have a project about how t write and implement the source
>codes of GREP function in the shell of UNIX

And where are you stuck?
  Parsing the command line?  (man getopt)
  Reading the input files?  (man fopen; man fgets)
  Matching a line against the provided RE? (man regcomp; man regexec;
    or maybe _this_ what you're supposed to be writing?)
  Something else?

                --Ken Pizzini

 
 
 

How to write GREP command in UNIX

Post by Randal L. Schwar » Fri, 03 Dec 1999 04:00:00


Maan> Hello everybody ,
Maan> I am a student in KFUPM
Maan> I have a project about how t write and implement the source
Maan> codes of GREP function in the shell of UNIX

Strictly using SHELL?  That's going to be a bit tough, even though
the shell is Turing-equivalent.

If you don't mean "strictly shell", then turn in this Perl program:

    #!/usr/bin/perl
    use Getopt::Std;
    my %opt;
    getopts('iVcle:',\%opt);
    my $pat = $opt{'e'} || shift;
    # warn "Matching /$pat/\n";


     {

     }
    my $count = 0;
    while (<>)
     {
      if (($opt{i})? /$pat/io : /$pat/o)
       {
        $count++;
        print "$ARGV:$.:$_" unless ($opt{'c'} || $opt{'l'});
       }
      if (eof)
       {
        printf("%5d $ARGV\n",$count) if ($opt{'V'} || $opt{'c'} && $count);
        print "$ARGV\n" if $opt{'l'};
        $count = 0;
        $. = 0;
       }
     }

(No, I didn't write it.  It's part of the PPT project.)

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095

Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

 
 
 

How to write GREP command in UNIX

Post by Tom Christianse » Sun, 05 Dec 1999 04:00:00



:I have a project about how t write and implement the source
:codes of GREP function in the shell of UNIX

http://language.perl.com/ppt/src/grep/index.html

--tom
--
There's no such thing as a simple cache bug. --Rob Pike
    "His super power is to turn into a scotch terrier."

 
 
 

1. How to make grep select both lines using only a single 'grep' command

: Hello,
:       We have an ASCII file called "ships" with lines in this format:

:       .....      3HO/3HA(PNTN) 4SD .....       [line 1]
:       .....      3HO/3HA 4SD .....             [line 2]
:       .                                        [line n]

:       The stuff in the parenthesis (the string "PNTN") can change.

:       Is there a single grep/egrep regular expression that can display
:       both lines?

:       I tried:

:       1. grep -i "3ho/3ha * 4s" ships,    showed line 2 only
:       2. grep -i "3ho/3ha* 4s" ships ,    showed line 2 only
:       3. grep -i "3ho/3ha *4s" ships ,    showed line 2 only
:       4. grep -i "3ho/3ha(*) 4s" ships,   showed nothing
:       5. grep -i "3ho/3ha(*) 4s" ships,   showed nothing
:       6. grep -i "3ho/3ha(p*) 4s" ships,  showed nothing

Remember that regular expressions and filename globbing are different things.
You were attempting filename globbing, when grep requires a regular expression.
Try this:

grep -i "3ho/3ha.* 4s" grepp

The ".*" does what you were trying to do with the "*", which is match a string
of 0 or more characters.

Beirne

--
Beirne Konarski         | Subscribe to the Unicycling Mailing List

Kent State University   | Unicycling Web Page:
"Untouched by Scandal"        | http://nimitz.mcs.kent.edu/~bkonarsk/

2. Obscure Error?

3. Help required: How to get unix to recognize two succesive spaces in grep command

4. kill process and child

5. How to rearrange a 'grep' command in LINUX to use in MATLAB with UNIX?

6. Linux for Embedded PC

7. grep search on command history file does not work on Tru64 Unix

8. How to get plip working?

9. Unix grep command?

10. Accessing Unix Command results through "C" (grep, ps, rsh)

11. multi-line grepping? (Digital Unix/OSF/1 *grep)

12. Use of grep and awk commands with iostat and mail commands

13. Best way to write plug-ins?