searching one file using the contents of another file 
Author Message
 searching one file using the contents of another file

Hello Group

I have been looking through Awk tutorials and it looks very usefull.
But I am looking to do the following: search a file X line-by-line,
using the line contents of another file Y of n lines.  that is, I
would search X n times, each time using a new line in Y as the
searched for string, and then generate a file Z of lines in X that
contained the searched for string consiting of the line in Y.  OK
thats a bit long-winded but hopefully very percise.

Is there a way to do this, either with Awk, or something else?  It
would be really helpfull.  Thank you in advance for any responses.



Wed, 09 Nov 2005 07:24:18 GMT  
 searching one file using the contents of another file

Quote:

>Hello Group

>I have been looking through Awk tutorials and it looks very usefull.
>But I am looking to do the following: search a file X line-by-line,
>using the line contents of another file Y of n lines.  that is, I
>would search X n times, each time using a new line in Y as the
>searched for string, and then generate a file Z of lines in X that
>contained the searched for string consiting of the line in Y.  OK
>thats a bit long-winded but hopefully very percise.

>Is there a way to do this, either with Awk, or something else?  It
>would be really helpfull.  Thank you in advance for any responses.

grep -f file_Y file_X > file_Z

isn't unix simple?

man grep

Chuck Demas

--
  Eat Healthy        |   _ _   | Nothing would be done at all,

  Die Anyway         |    v    | That no one could find fault with it.



Wed, 09 Nov 2005 09:15:03 GMT  
 searching one file using the contents of another file

X Hello Group
X
X I have been looking through Awk tutorials and it looks very usefull.
X But I am looking to do the following: search a file X line-by-line,
X using the line contents of another file Y of n lines.  that is, I
X would search X n times, each time using a new line in Y as the
X searched for string, and then generate a file Z of lines in X that
X contained the searched for string consiting of the line in Y.  OK
X thats a bit long-winded but hopefully very percise.
X
X Is there a way to do this, either with Awk, or something else?  It
X would be really helpfull.  Thank you in advance for any responses.

That was fun :-)

awk '
    first_file == "" || first_file == FILENAME {
        #
        # Capture the contents of the first file here
        #
        first_file = FILENAME
        patterns[count++] = $0
        next
    }

    #
    # we only get here if this is a line from the 2nd file
    #
    {
        for(j=0; j < count; j++) {
            if ( match($0,patterns[j]) ) {
                print $0
            }
        }
    }
' pattern.file data.file >output.file

                                        Bob Harris



Wed, 09 Nov 2005 09:45:41 GMT  
 searching one file using the contents of another file

Quote:
> But I am looking to do the following: search a file X line-by-line,
> using the line contents of another file Y of n lines.  that is, I
> would search X n times, each time using a new line in Y as the
> searched for string, and then generate a file Z of lines in X that
> contained the searched for string consiting of the line in Y.

perhaps:

   awk '{print"/"$0"/"}' Y | awk -f - X

(quoting may vary by shell)

Dan



Wed, 09 Nov 2005 11:15:20 GMT  
 searching one file using the contents of another file

Quote:

> man grep

I did, unfortunately I am not good enough at interperting manpages as
Id like to be.  Pretty simple solution there, nice.  I will decipher
the Awk scripts,  I will probably need Awk for generating nice
breakdowns of search script results.  Thanks very much for the
responses.


Thu, 10 Nov 2005 04:56:35 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Boolean searches of file content.

2. how to compile .vhd files one by one using makefile

3. compare one file contents to update another

4. Extracting Text file contents using Python

5. in-file search/replace question without using mv or cp

6. File search using TT's CatSearch Plugin

7. FYI - Re: Speed of searching file using Queues

8. CW2001.01 Search for number key using GET(file,key) PROBLEM

9. Using Debug to search a very large file?

10. Dropdown directory / file search using TCL 7.4 / TK 4.0

11. sourcing Tcl-files using some kind of search-path

12. number of records for tps file and searching files

 

 
Powered by phpBB® Forum Software