Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2003
    Posts
    9

    Unanswered: Unixware script question.

    Hi,

    This is probably a simple question:

    I have two files, "filea", and "fileb". "filea" contains a list of customer numbers only, one in each record.

    1234
    1241
    1250
    4569
    6433
    etc.

    "fileb" is a larger file containing the "complete" list of customer data with many more records in it, of which "filea" is a subset, that contains address info, phone, etc.

    I want to use the list of customer numbers in "filea" to extract those customer's data from "fileb" and output the result into "filec".

    I thought I could do something really simple like:

    grep `cat filea` fileb > filec

    but that didn't work. Any ideas?

    Thanks, Mike.

  2. #2
    Join Date
    Jun 2002
    Location
    UK
    Posts
    525

    Re: Unixware script question.

    grep `cat filea` fileb > filec
    You were on the right track.

    Use the -f flag with grep to pass in a list of patterns from a file.

    e.g.

    grep -f filea fileb > filec


    Just so you understand why your effort wouldn't work...

    `cat filea` would expand to for example:

    customer1
    customer2
    customer3

    ... your grep command would therefore be interpreted by the shell as being:

    grep customer1 customer2 customer3 fileb > filec

    The above would look for the pattern "customer1" in the files "customer2", "customer3" and "fileb". The output would be redirected to "filec". You would get errors in filec because the files you have stipulated do not exist.

    HTH
    Last edited by Damian Ibbotson; 09-12-03 at 12:51.

  3. #3
    Join Date
    Sep 2003
    Posts
    9

    Re: Unixware script question.

    Very nice... Thank you, this worked like a gem!


    Originally posted by Damian Ibbotson
    You were on the right track.

    Use the -f flag with grep to pass in a list of patterns from a file.

    e.g.

    grep -f filea fileb > filec


    Just so you understand why your effort wouldn't work...

    `cat filea` would expand to for example:

    customer1
    customer2
    customer3

    ... your grep command would therefore be interpreted by the shell as being:

    grep customer1 customer2 customer3 fileb > filec

    The above would look for the pattern "customer1" in the files "customer2", "customer3" and "fileb". The output would be redirected to "filec". You would get errors in filec because the files you have stipulated do not exist.

    HTH

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •