Indexing or Filtering code- Pattern Search by comparing two files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Indexing or Filtering code- Pattern Search by comparing two files
# 8  
Old 08-03-2008
New version of script (Assume first page is page 1):
Code:
awk '
BEGIN {
   print "Filtered Output Results";
   Page = 1;
}
NR==FNR {
   wlist[++wcount] = $1;
   words[$1] = 0;
   pages[$1] = "";
    last[$1] = 0;
   if (length($1) > wlen)
      wlen = length($1);
   next;
}
{
   for (i=1; i<=NF; i++) {
      if ($i in words)   {
         if (last[$i] != Page) {
            pages[$i] = pages[$i] Page " ";
             last[$i] = Page;
         }
      }
  }
}
NF>=2 && $(NF-1)=="Page" {
   if ($NF != Page)
      print "Page sequence error. Page",$NF,"must be",Page;
   Page = $NF + 1;
}
END {
   for (i=1; i<=wcount; i++) {
      w = wlist[i];
      printf("%-" wlen "s : %s\n", w, pages[w])
   }
}

' - aavam2.log

Keyword file (aavam.key)
Code:
bugs
output
for
full
and

Input log file (aavam.log)
Code:
LS(1)                            User Commands                           LS(1)



NAME
       ls - list directory contents

SYNOPSIS
       ls [OPTION]... [FILE]...

DESCRIPTION
       List  information  about  the FILEs (the current directory by default).
       Sort entries alphabetically if none of -cftuvSUX nor --sort.

       Mandatory arguments to long options are  mandatory  for  short  options
       too.

       -a, --all
              do not ignore entries starting with .
----------- Page 1

       -A, --almost-all
              do not list implied . and ..

       --author
              with -l, print the author of each file

       -b, --escape
              print octal escapes for nongraphic characters

       --block-size=SIZE
              use SIZE-byte blocks

       -B, --ignore-backups
              do not list implied entries ending with ~

       -c     with -lt: sort by, and show, ctime (time of last modification of
              file status information) with -l: show ctime and  sort  by  name
              otherwise: sort by ctime
----------- Page 2
. . . . . . . . 
----------- Page 11

COPYRIGHT
       Copyright (C) 2007 Free Software Foundation, Inc.
       This is free software.  You may redistribute copies  of  it  under  the
       terms       of       the      GNU      General      Public      License
       <http://www.gnu.org/licenses/gpl.html>.  There is NO WARRANTY,  to  the
       extent permitted by law.

SEE ALSO
       The  full  documentation  for ls is maintained as a Texinfo manual.  If
       the info and ls programs are properly installed at your site, the  com-
       mand

              info ls

       should give you access to the complete manual.



----------- Page 12
GNU coreutils 6.9                 March 2007                             LS(1)
----------- Page 13

Output:
Code:
Filtered Output Results
and    : 2 3 6 7 9 10 11 12
bugs   : 11
for    : 1 2 3 6 8 11 12
full   : 12
output : 3 7 10 11

# 9  
Old 08-03-2008
Page with Brackets [ ]

Cool... Thanks and it worked great as designed....Just wondering is there a particular variable that i could change in script for logs that have page numbers in brackets...For Eg as follows

[Page 1] .

Just trying to think of some other possibilities... You have been really helpful and thank you very much..
C. Smith
# 10  
Old 08-03-2008
Used the following option but no luck...
BEGIN {
Page = /^[-+]?[0-9]+$/ }

and

BEGIN {
Page = [Page 1]; }

and

BEGIN {
Page = `[:Page 1:]'

Nothing seems to be working....I am trying at my end...Any suggestions would be great...Thanks
# 11  
Old 08-04-2008
Modification to awk program :
Code:
NF>=2 && $(NF-1)=="[Page" {
   if ($NF+0 != Page)
      print "Page sequence error. Page",$NF,"must be",Page;
   Page = $NF + 1;
}

Jean-Pierre.
# 12  
Old 08-04-2008
Thank you...everything worked great.....C.Smith
# 13  
Old 11-11-2008
Hi ,

Sorry for incovinience, I need help how to post a query in the forum,
I couldn't fire a new query to forum,please tell me about the option

Regards
Shashi
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep/awk using a begin search pattern and end search pattern

I have this fileA TEST FILE ABC this file contains ABC; TEST FILE DGHT this file contains DGHT; TEST FILE 123 this file contains ABC, this file contains DEF, this file contains XYZ, this file contains KLM ; I want to have a fileZ that has only (begin search pattern for will be... (2 Replies)
Discussion started by: vbabz
2 Replies

2. Shell Programming and Scripting

Pattern search multiple files

#!/usr/bin/ksh a="Run successfully" cd $APPS ls -l *.txt | while read $txt do if then cp $APPS/$txt cp $hist/$txt else rm $APPS/$txt echo "Files has been removed" fi done New in shell script please help me out Around 100 txt files in $APPS dir i want to search pattern from... (8 Replies)
Discussion started by: Kalia
8 Replies

3. Shell Programming and Scripting

Search pattern in today's files only

Hi Friends, I am in search of unix command which can search a particular pattern in all files which are created/modified today ONLY. Which is the best way to achieve this? Thanks in advance. (1 Reply)
Discussion started by: Nakul_sh
1 Replies

4. Shell Programming and Scripting

To search the pattern on the basis of date and exit code

Hi, I am getting scheduler log file on daily basis from windows box which contains job status and corresponding date, date is in windows format. I wanted to write one script which will search the pattern (Exit code) for the today's date and if code is Zero then Job Success message should be... (14 Replies)
Discussion started by: ajju
14 Replies

5. Shell Programming and Scripting

Indexing each repeating pattern of rows in a column using awk/sed

Hello All, I have data like this in a column. 0 1 2 3 0 3 4 5 6 0 1 2 3 etc. where 0 identifies the start of a pattern in my data. So I need the output like below using either awk/sed. 0 1 (2 Replies)
Discussion started by: ks_reddy
2 Replies

6. Shell Programming and Scripting

[ask]filtering file to indexing...

dear all, i have file with format like this file_master.txt 20110212|231213|rio|apri|23112|222222 20110212|312311|jaka|dino|31223|543234 20110301|343322|alfan|budi|32131|333311 ... i want filter with output like this index_nm.txt rio|apri jaka|dino ... index_years.txt 20110212... (7 Replies)
Discussion started by: zvtral
7 Replies

7. Shell Programming and Scripting

awk script issue : comparing two files with a pattern

File 1 ################################################################# pma.zcal.iop_pma_zcal_cntl (2710.080 115.200) pma.lanea23.rx0.cntl (696.960 844.800) pma.lanea67.rx0.cntl (1733.760 844.800) pma.zcal.iop_pma_zcal_cust (2280.960 115.200)... (1 Reply)
Discussion started by: jaita
1 Replies

8. UNIX for Advanced & Expert Users

pattern search between 2 files

Afternoon guys, I have 2 files, 1.txt and 2.txt containing employee numbers. the 1st file (1.txt) is an extract from sybase with active employee numbers, the 2nd (2.txt) is a scan from the sybase log containing successfull logins *** which i have already mined and now contains only employee... (5 Replies)
Discussion started by: Jefferson333
5 Replies

9. UNIX for Dummies Questions & Answers

search all files for a pattern

Hi there, I am looking for a shell script which recursively searches all the files under all the directories for a pattern specified in the script. For e.g., i am looking forward to search for the file names which contains numbers of the form 001*****. Thanks in advance, Naik (4 Replies)
Discussion started by: ynaik002
4 Replies
Login or Register to Ask a Question