LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 07-09-2003, 10:49 PM   #1
powerplane
LQ Newbie
 
Registered: Apr 2003
Location: P.R. China
Distribution: FreeBSD 4.8 stable
Posts: 26

Rep: Reputation: 15
How to compare these two strings in one line code?


How to compare these two strings in one line code?

$> md5 -q 4.8-RELEASE-i386-mini.iso
5f0d2576dbb56d6ec85d49ac9fa4bbf9

$> awk '/mini/ {print $4}' CHECKSUM.MD5
5f0d2576dbb56d6ec85d49ac9fa4bbf9

How to compare those two output string in a neat command?
 
Old 07-10-2003, 12:19 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,005
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Re: How to compare these two strings in one line code?

Quote:
Originally posted by powerplane
How to compare these two strings in one line code?

$> md5 -q 4.8-RELEASE-i386-mini.iso
5f0d2576dbb56d6ec85d49ac9fa4bbf9

$> awk '/mini/ {print $4}' CHECKSUM.MD5
5f0d2576dbb56d6ec85d49ac9fa4bbf9

How to compare those two output string in a neat command?
Code:
$> expr `md5 -q 4.8-RELEASE-i386-mini.iso` = `awk '/mini/ {print $4}' CHECKSUM.MD5`
Something like that?

Cheers,
Tink
 
Old 07-10-2003, 12:33 AM   #3
powerplane
LQ Newbie
 
Registered: Apr 2003
Location: P.R. China
Distribution: FreeBSD 4.8 stable
Posts: 26

Original Poster
Rep: Reputation: 15
Yeah!
It works !
Another question , can I use "test" or "[ ]" do the same job ?

$> test 33 = 44
nothing happened

$> [ 33 = 44 ]
nothing happened
 
Old 07-10-2003, 12:58 AM   #4
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 46
You have to check the command's exit status. . .
A simple way (simple minded too) is to do the following:
Code:
[ 33 -eq 33 ] && echo boo
[ 33 -eq 34 ] && echo boo
Since && only evaluates the second command if the first's exit status is 0 (33 = 33 is true => exit(0)).
There are better ways of checking, but I'm too tired to look through my scripts. . .

I'm an idiot, a very tired idiot, but still an idiot.
Code:
if [ 33 -eq 34 ]; then echo "boo"; fi
If you want strings, use "=" instead of "-eq", of course.

Last edited by moses; 07-10-2003 at 12:59 AM.
 
Old 07-10-2003, 01:09 AM   #5
DrOzz
Senior Member
 
Registered: May 2003
Location: Sydney, Nova Scotia, Canada
Distribution: slackware
Posts: 4,185

Rep: Reputation: 59
and just because your not seeing any output, and the reasoning is behind what moses oringinally stated, your still not going to see any output with that line of code...just because 33 isn't equal to 34 so you won't see the output boo.....so instead of you responding and saying you still see no output, replace -eq with -ne just for you will see boo echoed back to you and you will finally be happy :P
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[C]How to compare two strings w/o using strcmp() kponenation Programming 22 11-23-2005 09:29 AM
File reading line by line and compare Goni Linux - Software 14 09-21-2005 01:24 AM
Search and Replace with multiple-line strings ChristianNerds.com Programming 4 08-21-2005 03:32 PM
how to compare 2 text files by using php code antony_csf Programming 3 10-14-2004 06:52 AM
Using diff to compare file with common lines, but at different line numbers jimieee Linux - Newbie 3 05-10-2004 08:26 AM


All times are GMT -5. The time now is 12:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration