APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

sed help!!

Got questions? Go ahead: Ask me anything!



Author: anonymous
Date: Thu Jul 27 13:42:36 2006
Subject: sed help!!

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..


GLIBC_VERSION_INFO=`rpm -q glibc`
GLIBC_VERSION=`echo ${GLIBC_VERSION_INFO}|sed`s///'

rakesh



Got something to add? Send me email.


11 comments



Increase ad revenue 50-250% with Ezoic


More Articles by © anonymous







Thu Jul 27 17:13:48 2006: 2291   TonyLawrence

gravatar
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

gravatar
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

gravatar
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

gravatar
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

gravatar
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)

------------------------
Kerio Samepage


Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

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





After growing wildly for years, the field of computing appears to be reaching its infancy. (John Pierce)





This post tagged: