×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Get second part of line with SED

Get second part of line with SED

Get second part of line with SED

(OP)

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.

RE: Get second part of line with SED

(OP)

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

RE: Get second part of line with SED

(OP)

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
$

RE: Get second part of line with SED

(OP)
That did it!  Thank you!!!

RE: Get second part of line with SED

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
?
 

RE: Get second part of line with SED

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close