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.


Hate these ads?

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



Comments /Forum/anonymous38.html


Thu Jul 27 17:13:48 2006: Subject:   TonyLawrence
If I'm understanding you correctly, you want:



rpm -q glibc | sed 's/glibc-\(...\).*/\1/'

Fri Jul 28 11:56:04 2006: Subject:   anonymous
(your comments go here)



Hey Tony.... Thats great man. Aceppt a haertly thanks from me

Mon Jul 31 10:50:35 2006: Subject:   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: Subject:   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: Subject:   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: Subject:   anonymous
(your comments go here)



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: Subject:   TonyLawrence
If you'd prefer what you don't have, use a language that has what you prefer.



M3IP inc.



Mon Jul 31 13:17:47 2006: Subject:   anonymous
(your comments go here)



Aah!! I was expecting a terse reply from you... Anyway thanks man. I would surely explore.... Thanks

Mon Jul 31 15:49:07 2006: Subject:   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: Subject:   anonymous
(your comments go here)


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: Subject:   TonyLawrence
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".



Add your comments

Enter your email address for automatic notification of new posts here
(be sure to whitelist 'feedburner.com' if you use spam filtering)

Or use any RSS reader

Delivered by FeedBurner


Views for this page
Today This Week This Month This Year  Overall
5827908 7,697

/Forum/anonymous38.html copyright July 2006 anonymous All Rights Reserved

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

More:
       - Forum




Unix/Linux Consultants

Your ad here - $24.00 yearly!

http://www.m3ipinc.com Security, firewalls, ids, audits, vulnerability assesments, BS7799, HIPAA, GLB, incident handling


http://bcstechnology.net Full service Linux & UNIX systems integrator; Windows to UNIX/Linux Client-Server Specialist; Secure E-Mail & Website Hosting; Thoroughbred Software Developer; Custom Industrial Automation; Hardware & Electronics Experts; In Business Since 1985.


http://www.vss3.com SCO/Caldera OpenServer, Unixware & Linux. Tarantella & Non-stop Clustering




card_image








Change Congress


Related Posts