LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-03-2012, 03:31 PM   #1
patmut
LQ Newbie
 
Registered: Jun 2011
Posts: 8

Rep: Reputation: Disabled
Unhappy Extract the first numeric character from a string


Folks,

I'm writing a small script that should test RHEL version of a system (5.x or 6.x) and then execute a specific ation depending on the version. I'd like to test the condition on the fisrt numeric value to extract from 'cat /etc/redhat-release'. Does someone can help me with the command to extract this first numeric character (i.e. 5 or 6) and assign it to a variable?

Patmut
 
Old 07-03-2012, 04:25 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by patmut View Post
Folks,
I'm writing a small script that should test RHEL version of a system (5.x or 6.x) and then execute a specific ation depending on the version. I'd like to test the condition on the fisrt numeric value to extract from 'cat /etc/redhat-release'. Does someone can help me with the command to extract this first numeric character (i.e. 5 or 6) and assign it to a variable?
What have you done/tried so far??? The best help would be for you to read bash scripting tutorials, which will give you help for this and MANY other scripting problems:
http://tldp.org/LDP/abs/html/

Some hints would be to read the man pages on the cut command.
 
Old 07-04-2012, 03:29 AM   #3
patmut
LQ Newbie
 
Registered: Jun 2011
Posts: 8

Original Poster
Rep: Reputation: Disabled
Thanks for the hint.
In the meantime, I sorted it out with this command : grep -o [[:digit:]] /etc/redhat-release | head -n 1
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
convert string date to numeric j-me Linux - Server 3 06-15-2012 02:03 PM
[SOLVED] bash thinks string variable is a numeric one. stf92 Programming 11 07-08-2011 01:35 AM
SQL -any value for numeric or string field kpachopoulos Programming 2 02-12-2010 10:53 AM
Split string and numeric with perl kariagekun Programming 4 11-05-2009 07:31 PM
problem in comparing numeric with string naren_0101bits Programming 1 01-28-2008 08:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:53 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
Open Source Consulting | Domain Registration