If u type
--- rpm -q glibc
--- glibc-2.3.3-74
I want to extrac (2.x) from the string and store in a variable. How can I do that.
I have started something like this... Its a shell script.. can anybody help me out..
rakesh
Got something to add? Send me email.
More Articles by anonymous © 2009-11-07 anonymous
As an experimental psychologist, I have been trained not to believe anything unless it can be demonstrated in the laboratory on rats or sophomores. (Steven Pinker)
Thu Jul 27 17:13:48 2006: 2291 TonyLawrence
If I'm understanding you correctly, you want:
rpm -q glibc | sed 's/glibc-\(...\).*/\1/'
Fri Jul 28 11:56:04 2006: 2295 anonymous
Hey Tony.... Thats great man. Aceppt a haertly thanks from me
Mon Jul 31 10:50:35 2006: 2323 anonymous
Tony, I would like to bug you a bit more.... Here is what I am trying to do..
#!/bin/bash
UNAME_MACHINE=`uname -m`
UNAME_KERNAL=`uname -s`
GLIB_QUERY=`rpm -q glibc`
GLIBC_VERSION_INFO=`echo ${GLIB_QUERY} | sed 's/glibc-\(...\).*/\1/'`
GLIBC_VERSION=0
echo $GLIBC_VERSION_INFO
if [ $GLIBC_VERSION_INFO -ge 2.3 ]; then
GLIBC_VERSION=30
elif [ $GLIBC_VERSION_INFO -lt 2.2 ]; then
GLIBC_VERSION=21
else
GLIBC_VERSION=0
fi
echo $GLIBC_VERSION
if [ $GLIBC_VERSION -eq 0 ]
then
echo $UNAME_MACHINE"_"$UNAME_KERNAL
else
echo $UNAME_MACHINE"_"$UNAME_KERNAL"_"$GLIBC_VERSION
Mon Jul 31 10:51:49 2006: 2324 anonymous
But it is cribbing with the below errors :-
./platform.sh: line 12: [: 2.3: integer expression expected
./platform.sh: line 14: [: 2.3: integer expression expected
Mon Jul 31 11:40:44 2006: 2325 TonyLawrence
Read the man page for "test". You are trying to compare strings to integers with an integer comparison operator. You need to use string comparion (=, <, >) and put your numbers in quotes to make them strings.
Mon Jul 31 12:46:00 2006: 2326 anonymous
But with string only = and != operators are allowed!!
Is there something like typecast as well for scripting langauges, I would prefer to typecast string to integer.
Mon Jul 31 13:03:59 2006: 2327 TonyLawrence
If you'd prefer what you don't have, use a language that has what you prefer.
Mon Jul 31 13:17:47 2006: 2328 anonymous
Aah!! I was expecting a terse reply from you... Anyway thanks man. I would surely explore.... Thanks
Mon Jul 31 15:49:07 2006: 2330 TonyLawrence
Sorry to be terse, but really: I don't write anything but one liners in shell - if it's at all complicated - even just a little - I use Perl.
You should use a language that you like..
Tue Aug 1 08:50:44 2006: 2336 anonymous
Tony, I am very impressed. You are a great human-being. I have never expected an answer from you. And you are very humble. In our mother-tongue(HINDI), there is proverb.. which means "knowledge makes a person humble" and so you are!!
Great job dude.... carry on!!
Tue Aug 1 10:41:15 2006: 2337 TonyLawrence
Well, I should have also mentioned that bash does let you typecast strings to integers. See the man or info pages and look at "declare". (link)
------------------------
Printer Friendly Version
sed help!! Copyright © July 2006 anonymous
Have you tried Searching this site?
This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.
Contact us
Printer Friendly Version