On Saturday 08 April 2006 01:08, Alan_C wrote:
> On Friday 07 April 2006 03:34, John W. Krahn wrote:
> > Alan_C wrote:
> > > Hi,
> >
> > Hello,

Hi.  Thanks for the help.  I've got a (Linux platform) working solution with 
the improvements that I mentioned are onto it.

When searching (enter on commandline) multiple words it can print out several 
listings of the same xtst file due to I use some cross referencing of my 
keywords in the xtst files.  I'd like for it to not list out a particular 
xtst file more than once -- will see what I can do on this.

If anyone want to play with it, it works by: 1. have your xtst01, xtst02, 
xtst03, etc. text files in a folder  2. have a keyword line in each of these 
files this line is to be located within 9 lines from the top of each of the 
files.  3. run the index creator script to create a file named index  4. now 
run grepf and enter one, two, or three words or so on the commandline.

To create the index file:

[EMAIL PROTECTED]:~$ indexcreater > index

When the xtst data files are edited or added to is the only time that you need 
to run indexcreater again so as to get the index file updated.

To run grepf [ grepf keyword(s) ], thus:

[EMAIL PROTECTED]:~$ grepf array push list

A sample keyword line looks like this (must begin with #:):

#: array arrays functions push pop shift list

Here's some example xtst text files:

# xtst01
#: array arrays functions push pop shift list
however many lines of info goes here
#------- end of xtst01 ---------

# xtst02
#: push syntax example
however many lines of info goes here
#------- end of xtst02 ---------

# xtst03
#: split syntax example examples
however many lines of info goes here
#------- end of xtst03 ---------

Here's the index creater:

#!/usr/bin/perl -w
use strict;

@ARGV = glob 'xtst*';

while (<>) {
    if (m/^\#:/g) {
        s/^\#://;
        print $ARGV, $_;
    }

    # quit looking when we reach the ninth line
    close ARGV if $. == 9;
} # end

#---------------------------------------------------------------
Here's grepf:

#!/usr/bin/perl -w
use strict;

# grepf
my $size = @ARGV;
# print $size, "\n";

my @search4 = @ARGV;    # keywords
@ARGV = ();

# print @search4, "\n";

@ARGV = 'index';

my @list;
my $filename;
my $keyline;
my $wherefound;
my $found_tally = 0 ;
while (<>) {
    $keyline  = $_;
    @list     = split;
    $filename = shift @list;
    foreach (@list) {
        for ( my $i = 0 ; $i < $size ; $i++ ) {
            if (/$search4[$i]/) {
                $found_tally++;
                print "$found_tally '$search4[$i]' found in:\n";
#                print $filename, "\n";
#                print @list, "\n\n";
                print "$keyline\n\n";
                $wherefound .= $filename . " ";
            }
        }
    }
}
$wherefound =~ s/\s$//;
print "wherefound '$wherefound'\n";
my @foundin = split(/ /, $wherefound);
# print @foundin, "\n";
print "\nenter a digit: ";
chomp(my $d = <STDIN>);
$d = $d-1;
print $foundin[$d], "\n";
system("cat $foundin[$d]");
# end

-- 
Alan.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to