Sponsored Content
Top Forums Shell Programming and Scripting Indexing or Filtering code- Pattern Search by comparing two files Post 302221039 by aigles on Sunday 3rd of August 2008 04:23:47 AM
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 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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

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

7. 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

8. 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

9. 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
platform::shell(n)					       Tcl Bundled Packages						platform::shell(n)

__________________________________________________________________________________________________________________________________________________

NAME
platform::shell - System identification support code and utilities SYNOPSIS
package require platform::shell ?1.1.4? platform::shell::generic shell platform::shell::identify shell platform::shell::platform shell _________________________________________________________________ DESCRIPTION
The platform::shell package provides several utility commands useful for the identification of the architecture of a specific Tcl shell. This package allows the identification of the architecture of a specific Tcl shell different from the shell running the package. The only requirement is that the other shell (identified by its path), is actually executable on the current machine. While for most platform this means that the architecture of the interrogated shell is identical to the architecture of the running shell this is not generally true. A counter example are all platforms which have 32 and 64 bit variants and where a 64bit system is able to run 32bit code. For these running and interrogated shell may have different 32/64 bit settings and thus different identifiers. For applications like a code repository it is important to identify the architecture of the shell which will actually run the installed packages, versus the architecture of the shell running the repository software. COMMANDS
platform::shell::identify shell This command does the same identification as platform::identify, for the specified Tcl shell, in contrast to the running shell. platform::shell::generic shell This command does the same identification as platform::generic, for the specified Tcl shell, in contrast to the running shell. platform::shell::platform shell This command returns the contents of tcl_platform(platform) for the specified Tcl shell. KEYWORDS
operating system, cpu architecture, platform, architecture platform::shell 1.1.4 platform::shell(n)
All times are GMT -4. The time now is 07:07 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy