Find the answer to your Linux question:
Results 1 to 6 of 6
I have two md5 strings that i wish to compare. i don't want to do this manually so have been attempting to use either "cmp" or "diff". I would like ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined! hush's Avatar
    Join Date
    Oct 2006
    Posts
    18

    comparing standard input


    I have two md5 strings that i wish to compare. i don't want to do this manually so have been attempting to use either "cmp" or "diff".

    I would like to do it from standard input rather than files.

    The best i have come up with so far is
    Code:
    diff file1 -
    which compares the operand to STDIN but I was wondering if there was a way to do it with two lots of STDIN (using "cmp" "diff" or any other tool).

  2. #2
    Linux Engineer RobinVossen's Avatar
    Join Date
    Aug 2007
    Location
    The Netherlands
    Posts
    1,429
    What about:
    Code:
    First=read
    Second=read
    diff $First $Second
    Or, I might not get your Question
    New Users, please read this..
    Google first, then ask..

  3. #3
    Just Joined! hush's Avatar
    Join Date
    Oct 2006
    Posts
    18
    thanks for the reply.

    i would like to compare two strings rather then files. the following output my make it a bit clearer:

    Code:
    ~$ First=f79fa5a676b6dddb5ef48f9041771377
    ~$ Second=f79fa5a676b6dddb5ef48f9041771377
    ~$ diff $First $Second
    diff: f79fa5a676b6dddb5ef48f9041771377: No such file or directory
    diff: f79fa5a676b6dddb5ef48f9041771377: No such file or directory

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Engineer RobinVossen's Avatar
    Join Date
    Aug 2007
    Location
    The Netherlands
    Posts
    1,429
    Oh yea ofc.
    My bad well do it like this:
    Code:
    First=read
    Second=read
    echo $First >> $First 
    echo $Second >> $Second
    diff $First $Second
    rm -rf  $First $Second
    New Users, please read this..
    Google first, then ask..

  6. #5
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Slackware, {Free, Open, Net}BSD, Solaris
    Posts
    1,294
    Hi.

    I would use the shell. Get the strings into variables as you need, then compare:
    Code:
    #!/usr/bin/env sh
    
    # @(#) s1       Demonstrate string compare.
    
    set -o nounset
    echo
    
    debug=":"
    debug="echo"
    
    ## Use local command version for the commands in this demonstration.
    
    echo "(Versions displayed with local utility \"version\")"
    version >/dev/null 2>&1 && version bash
    
    echo
    First=f79fa5a676b6dddb5ef48f9041771377
    Second=f79fa5a676b6dddb5ef48f9041771377
    
    echo " Expecting OK:"
    if [ "$First" = "$Second" ]
    then
            echo OK
    else
            echo KO
    fi
    
    echo
    echo " Expecting KO:"
    First=9
    if [ "$First" = "$Second" ]
    then
        echo OK
    else
        echo KO
    fi
    
    exit 0
    Producing:
    Code:
    % ./s1
    
    (Versions displayed with local utility "version")
    GNU bash 2.05b.0
    
     Expecting OK:
    OK
    
     Expecting KO:
    KO
    cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  7. #6
    Linux Engineer RobinVossen's Avatar
    Join Date
    Aug 2007
    Location
    The Netherlands
    Posts
    1,429
    Thats better indeed
    New Users, please read this..
    Google first, then ask..

Posting Permissions

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