Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get second part of line with SED 1

Status
Not open for further replies.

blarneyme

MIS
Jun 22, 2009
160
0
0
US
Code:
cat /etc/*release
Red Hat Enterprise Linux Server release 5.8 (Tikanga)

cat /etc/*release 
Red Hat Enterprise Linux ES release 4 (Nahant Update 9)

I want to extract just 5.8 or 4

I have used
Code:
cat /etc/*release | sed 's/\(.*\)\([0-9]\{1\}.?[0-9]\?\)\((.*)\)/\2/'
but it returns the entire line.

Code:
cat /etc/*release | sed 's/\(.*\)\([0-9]\{1\}.\?[0-9]\?\)\(.*\)/\2/'
returns just 8 from 5.8 and 9 from the RHEL 4 line.
 
Code:
cat /etc/*release | sed 's/\(.*\)\([0-9]\{1\}.\?[0-9]\{1,\}\)\(.*\)/\2/'
Correctly returns 5.8 but still returns the entire line for RHEL 4
 
What about this ?
Code:
sed 's/.*\([0-9]\{1\}\.\?[0-9]*\).*/\1/' /etc/*release

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Code:
# cat /etc/*release
Red Hat Enterprise Linux Server release 5.8 (Tikanga)
# sed 's/.*\([0-9]\{1\}\.\?[0-9]*\).*/\1/' /etc/*release
8
#

$ cat /etc/*release
Red Hat Enterprise Linux ES release 4 (Nahant Update 9)
$ sed 's/.*\([0-9]\{1\}\.\?[0-9]*\).*/\1/' /etc/*release
9
$
 
And this ?
Code:
sed 's/.* \([0-9]\{1\}\.\?[0-9]*\) .*/\1/' /etc/*release

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
First, the suggested solutions won't work with:
release 10.1
Or
release release 4 (Nahant Update 9 extended)

What about
Code:
sed 's/.*release \([^ ]*\) .*/\1/' /etc/*release
?
 
An AWK solution....dont bite, i'm just bored

Code:
awk '{for(i=1;i<NF;i++)if($i=="release") print $(i+1)}' /etc/*release
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top