Results 1 to 5 of 5
  1. #1
    Join Date
    May 2009
    Posts
    43

    Unanswered: Reading one variable from one file, checking whether it is existing in another file

    Hi,

    I have a table from which I can get the list of servers. This I am placing in one file (abc). I have one another file (say "xyz) with the list of servers (this is not from the table I am talking above).

    Here I have to get the server names one by one from file "abc" and check whether the same is existing in the file "xyz".

    For example :

    file "abc" has
    ---------
    PPMPDB
    HPRD8
    TFRCST
    DFPDB
    RXPPDB
    SBOPDB
    UCDP
    ALGPDB
    SMTP
    SRMP
    RMANREP
    FPRD

    file "xyz" has
    -------------
    PPMPDB
    HPRD8
    TFRCST
    DFPDB
    RXPPDB
    SBOPDB
    UCDP

    Here "abc" and "xyz" are not same. wherever it is not matching I have to print msg.

    Please let me know how to put this in script.

    Regards,
    Vineela

  2. #2
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    Try the following command and filtering the output.
    Code:
    diff abc xyz

  3. #3
    Join Date
    May 2009
    Posts
    43
    I can not do that here.

    For example:

    If the file1 has first two rows as follows

    abcd
    wxyz

    and the file2 has

    wxyz
    abcd

    If i execute "diff" command, i will get the difference like two are not same.
    My requirement is, I have to check the word "abcd" in file2 (irrespective of the row number).

    Hope my requirement is now clear.

  4. #4
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    Code:
    while read a
    do
    grep $a xyz
    if [ $? -ne 0 ]
    then
    echo $a does not exist in xyz
    fi
    done <abc
    Last edited by kitaman; 01-12-10 at 09:28.

  5. #5
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    or even:
    Code:
    sort abc > sorted_abc
    sort xyz > sorted_xyz
    diff sorted_abc sorted_xyz

Posting Permissions

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