Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to capture only 7 or 8 in /etc/redhat-release

115 views
Skip to first unread message

Neeraj Kumar

unread,
Jun 5, 2023, 8:23:31 AM6/5/23
to
I have two version; please help me to get the version in the form of 7 or 8

Chris Elvidge

unread,
Jun 5, 2023, 8:49:02 AM6/5/23
to
On 05/06/2023 13:23, Neeraj Kumar wrote:
> I have two version; please help me to get the version in the form of 7 or 8
>

grep -o -E "7|8" /etc/redhat-release

--
Chris Elvidge
England

Neeraj Kumar

unread,
Jun 5, 2023, 9:14:11 AM6/5/23
to
Thank you for the reply..
if the Linux is 8.7 then it will not give proper output.

can we have this by awk command .. I tried multiple but unlucky to get in single line

Ben Bacarisse

unread,
Jun 5, 2023, 9:36:36 AM6/5/23
to
Chris Elvidge <ch...@mshome.net> writes:

> On 05/06/2023 13:23, Neeraj Kumar wrote:
>> I have two version; please help me to get the version in the form of 7 or 8
>>
>
> grep -o -E "7|8" /etc/redhat-release

This will say 7 for release 6.7 (not that I know there ever was such a
release number) but even given the OPs restriction to 7 or 8, version
7.8 will give two lines.

One way (if one's grep has them) would be to use Perl REs and employ a
"lookbehind" assertion:

grep -o -P '(?<=release )\d+' /etc/redhat-release

but then it's not at all clear what OP really wants.

To the OP: it's generally better to look in /etc/os-release.

--
Ben.

Janis Papanagnou

unread,
Jun 5, 2023, 9:55:49 AM6/5/23
to
On 05.06.2023 15:14, Neeraj Kumar wrote:
> On Monday, June 5, 2023 at 6:19:02 PM UTC+5:30, Chris Elvidge wrote:
>> On 05/06/2023 13:23, Neeraj Kumar wrote:
>>> I have two version; please help me to get the version in the form of 7 or 8
>>>
>> grep -o -E "7|8" /etc/redhat-release
>>
>> --
>> Chris Elvidge
>> England
>
> Thank you for the reply..
> if the Linux is 8.7 then it will not give proper output.

You could use sed for the extraction of the number

echo " 8.7 "| sed 's/.*\([78]\)[.].*/\1/'

or shell's expr

expr " 8.7 " : '.*\([78]\)[.].*'

(In both cases taking the digit 7 or 8 in front of a literal dot.)

>
> can we have this by awk command .. I tried multiple but unlucky to get in single line

Why awk?

With Ben's suggestion for the source of the version information

awk -F[=\".] '/VERSION=/{print $3}' /etc/os-release

(can of course also done with sed or shell in a most simple way).

Janis

Janis Papanagnou

unread,
Jun 5, 2023, 9:57:30 AM6/5/23
to
On 05.06.2023 15:55, Janis Papanagnou wrote:
>
> or shell's expr

Erm.. - it's not a shell built-in but an ordinary command.

Janis

David W. Hodgins

unread,
Jun 5, 2023, 12:28:41 PM6/5/23
to
On Mon, 05 Jun 2023 08:23:27 -0400, Neeraj Kumar <neeraj.fr...@gmail.com> wrote:

> I have two version; please help me to get the version in the form of 7 or 8

Why use /etc/redhat-release? /etc/lsb-release is more likely to be found in
various distributions, and is easier to parse in bash.

$ . /etc/lsb-release
$ echo $DISTRIB_RELEASE
8
$ echo $DISTRIB_ID
Mageia

Regards, Dave Hodgins

Kaz Kylheku

unread,
Jun 5, 2023, 12:29:14 PM6/5/23
to
On 2023-06-05, Neeraj Kumar <neeraj.fr...@gmail.com> wrote:
> On Monday, June 5, 2023 at 6:19:02 PM UTC+5:30, Chris Elvidge wrote:
>> On 05/06/2023 13:23, Neeraj Kumar wrote:
>> > I have two version; please help me to get the version in the form of 7 or 8
>> >
>> grep -o -E "7|8" /etc/redhat-release
>>
>> --
>> Chris Elvidge
>> England
>
> Thank you for the reply..
> if the Linux is 8.7 then it will not give proper output.

If Linux is 8.7, today can't be 2023. The current stable version is
6.3.6, with a 6.4-rc5 (release candidate 5) on the mainline.

See https://kernel.org


--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazi...@mstdn.ca

Bit Twister

unread,
Jun 5, 2023, 1:15:18 PM6/5/23
to
Or the op could do something like
$ . /etc/os-release
$ echo $VERSION
or
$ echo $VERSION_ID


Keith Thompson

unread,
Jun 5, 2023, 1:31:03 PM6/5/23
to
Neeraj Kumar <neeraj.fr...@gmail.com> writes:
> I have two version; please help me to get the version in the form of 7 or 8

Please show us the content of /etc/redhat-release.

--
Keith Thompson (The_Other_Keith) Keith.S.T...@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

Keith Thompson

unread,
Jun 5, 2023, 1:33:12 PM6/5/23
to
Kaz Kylheku <864-11...@kylheku.com> writes:
> On 2023-06-05, Neeraj Kumar <neeraj.fr...@gmail.com> wrote:
[...]
>> if the Linux is 8.7 then it will not give proper output.
>
> If Linux is 8.7, today can't be 2023. The current stable version is
> 6.3.6, with a 6.4-rc5 (release candidate 5) on the mainline.
>
> See https://kernel.org

Kaz's point is that Linux (the kernel) and Red Hat (the operating
system) are two different things with different version numbers.
/etc/redhat-release has information about the OS.

Kaz Kylheku

unread,
Jun 5, 2023, 2:56:48 PM6/5/23
to
On 2023-06-05, Keith Thompson <Keith.S.T...@gmail.com> wrote:
> Kaz Kylheku <864-11...@kylheku.com> writes:
>> On 2023-06-05, Neeraj Kumar <neeraj.fr...@gmail.com> wrote:
> [...]
>>> if the Linux is 8.7 then it will not give proper output.
>>
>> If Linux is 8.7, today can't be 2023. The current stable version is
>> 6.3.6, with a 6.4-rc5 (release candidate 5) on the mainline.
>>
>> See https://kernel.org
>
> Kaz's point is that Linux (the kernel) and Red Hat (the operating
> system) are two different things with different version numbers.
> /etc/redhat-release has information about the OS.

Unlike some, I don't have a problem with Red Hat being called a
"Linux distribution", but when you start talking about it it being
Linux 8.7, we have crossed the blurry line between political
and stupid.

Keith Thompson

unread,
Jun 5, 2023, 4:16:32 PM6/5/23
to
Kaz Kylheku <864-11...@kylheku.com> writes:
> On 2023-06-05, Keith Thompson <Keith.S.T...@gmail.com> wrote:
>> Kaz Kylheku <864-11...@kylheku.com> writes:
>>> On 2023-06-05, Neeraj Kumar <neeraj.fr...@gmail.com> wrote:
>> [...]
>>>> if the Linux is 8.7 then it will not give proper output.
>>>
>>> If Linux is 8.7, today can't be 2023. The current stable version is
>>> 6.3.6, with a 6.4-rc5 (release candidate 5) on the mainline.
>>>
>>> See https://kernel.org
>>
>> Kaz's point is that Linux (the kernel) and Red Hat (the operating
>> system) are two different things with different version numbers.
>> /etc/redhat-release has information about the OS.
>
> Unlike some, I don't have a problem with Red Hat being called a
> "Linux distribution", but when you start talking about it it being
> Linux 8.7, we have crossed the blurry line between political
> and stupid.

My point was not about the politics of referring to a distribution as
"Linux". My point was that the person you were addressing might not
have understood what you were talking about.

Neeraj wrote something incorrect. That doesn't imply they're stupid.

Richard Harnden

unread,
Jun 6, 2023, 6:51:01 AM6/6/23
to
On 05/06/2023 18:30, Keith Thompson wrote:
> Neeraj Kumar <neeraj.fr...@gmail.com> writes:
>> I have two version; please help me to get the version in the form of 7 or 8
>
> Please show us the content of /etc/redhat-release.
>

This is what I have. They dropped 'Server' for version 8 ...

Red Hat Enterprise Linux Server release 5.6 (Tikanga)
Red Hat Enterprise Linux Server release 5.8 (Tikanga)
Red Hat Enterprise Linux Server release 5.11 (Tikanga)
Red Hat Enterprise Linux Server release 6.4 (Santiago)
Red Hat Enterprise Linux Server release 6.6 (Santiago)
Red Hat Enterprise Linux Server release 6.7 (Santiago)
Red Hat Enterprise Linux Server release 6.8 (Santiago)
Red Hat Enterprise Linux Server release 6.9 (Santiago)
Red Hat Enterprise Linux Server release 6.10 (Santiago)
Red Hat Enterprise Linux Server release 7.4 (Maipo)
Red Hat Enterprise Linux Server release 7.6 (Maipo)
Red Hat Enterprise Linux Server release 7.7 (Maipo)
Red Hat Enterprise Linux Server release 7.9 (Maipo)
Red Hat Enterprise Linux release 8.1 (Ootpa)
Red Hat Enterprise Linux release 8.3 (Ootpa)
Red Hat Enterprise Linux release 8.4 (Ootpa)
Red Hat Enterprise Linux release 8.6 (Ootpa)

Also, CentOs ...

CentOS Linux release 7.9.2009 (Core)
CentOS Stream release 8

/etc/os-release doesn't seem to exist prior to version 7, and CentOs
Stream dropped the decimal-point - but VERSION_ID is the easiest to parse.







Keith Thompson

unread,
Jun 6, 2023, 2:35:32 PM6/6/23
to
Richard Harnden <richard...@gmail.com> writes:
> On 05/06/2023 18:30, Keith Thompson wrote:
>> Neeraj Kumar <neeraj.fr...@gmail.com> writes:
>>> I have two version; please help me to get the version in the form of 7 or 8
>> Please show us the content of /etc/redhat-release.
>>
>
> This is what I have. They dropped 'Server' for version 8 ...
>
> Red Hat Enterprise Linux Server release 5.6 (Tikanga)
> Red Hat Enterprise Linux Server release 5.8 (Tikanga)
[SNIP]
> Red Hat Enterprise Linux release 8.4 (Ootpa)
> Red Hat Enterprise Linux release 8.6 (Ootpa)
>
> Also, CentOs ...
>
> CentOS Linux release 7.9.2009 (Core)
> CentOS Stream release 8
>
> /etc/os-release doesn't seem to exist prior to version 7, and CentOs
> Stream dropped the decimal-point - but VERSION_ID is the easiest to
> parse.

Is /etc/redhat-release always just one line? (Similar files like
/etc/lsb-release are several lines.)

Richard Harnden

unread,
Jun 6, 2023, 2:55:50 PM6/6/23
to
On 06/06/2023 19:35, Keith Thompson wrote:
> Richard Harnden <richard...@gmail.com> writes:
>> On 05/06/2023 18:30, Keith Thompson wrote:
>>> Neeraj Kumar <neeraj.fr...@gmail.com> writes:
>>>> I have two version; please help me to get the version in the form of 7 or 8
>>> Please show us the content of /etc/redhat-release.
>>>
>>
>> This is what I have. They dropped 'Server' for version 8 ...
>>
>> Red Hat Enterprise Linux Server release 5.6 (Tikanga)
>> Red Hat Enterprise Linux Server release 5.8 (Tikanga)
> [SNIP]
>> Red Hat Enterprise Linux release 8.4 (Ootpa)
>> Red Hat Enterprise Linux release 8.6 (Ootpa)
>>
>> Also, CentOs ...
>>
>> CentOS Linux release 7.9.2009 (Core)
>> CentOS Stream release 8
>>
>> /etc/os-release doesn't seem to exist prior to version 7, and CentOs
>> Stream dropped the decimal-point - but VERSION_ID is the easiest to
>> parse.
>
> Is /etc/redhat-release always just one line? (Similar files like
> /etc/lsb-release are several lines.)
>

Yes, it's always one line.

Pyt T.

unread,
Jun 7, 2023, 3:25:53 AM6/7/23
to
On Tue, 6 Jun 2023 11:50:53 +0100, Richard Harnden <richard...@gmail.com> wrote:
> Red Hat Enterprise Linux Server release 5.6 (Tikanga)
> Red Hat Enterprise Linux Server release 5.8 (Tikanga)
> Red Hat Enterprise Linux Server release 5.11 (Tikanga)
> Red Hat Enterprise Linux Server release 6.4 (Santiago)
> Red Hat Enterprise Linux Server release 6.6 (Santiago)
> Red Hat Enterprise Linux Server release 6.7 (Santiago)
> Red Hat Enterprise Linux Server release 6.8 (Santiago)
> Red Hat Enterprise Linux Server release 6.9 (Santiago)
> Red Hat Enterprise Linux Server release 6.10 (Santiago)
> Red Hat Enterprise Linux Server release 7.4 (Maipo)
> Red Hat Enterprise Linux Server release 7.6 (Maipo)
> Red Hat Enterprise Linux Server release 7.7 (Maipo)
> Red Hat Enterprise Linux Server release 7.9 (Maipo)
> Red Hat Enterprise Linux release 8.1 (Ootpa)
> Red Hat Enterprise Linux release 8.3 (Ootpa)
> Red Hat Enterprise Linux release 8.4 (Ootpa)
> Red Hat Enterprise Linux release 8.6 (Ootpa)

If I parse this list through:
sed 's/.*release \([^(]*\)(.*/\1/'

I get:
5.6
5.8
5.11
6.4
6.6
6.7
6.8
6.9
6.10
7.4
7.6
7.7
7.9
8.1
8.3
8.4
8.6

Pyt T.

unread,
Jun 7, 2023, 3:34:04 AM6/7/23
to
Use:
sed 's/.*\([0-9]\)\..*/\1/'

to get:
5
5
5
6
6
6
6
6
6
7
7
7
7
8
8
8
8
0 new messages