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











(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Printer Friendly Version


sed help!!



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



If this page was useful to you, please help others find it:  





11 comments




More Articles by anonymous



Click here to add your comments





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 shouls have also mentioned that bash does let you typecast strings to integers. See the man or info pages and look at "declare".

Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar



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. We appreciate comments and article submissions.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.

g_face.jpg

This post tagged:

       - Forum
       - SED
       - Scripting
       - Shell






















My Troubleshooting E-Book will show you how to solve tough problems on Linux and Unix systems!


book graphic unix and linux troubleshooting guide



Buy Kerio from a dealer
who knows tech:
I sell and support

Kerio Connect Mail server, Control, Workspace and Operator licenses and subscription renewals