How to select a number?
cat /etc/redhat-release
return:
CentOS Linux release 5.6.1804 (Core)
how do I select the first number I've only tried
cat /etc/redhat-release | awk '{print $4}'
and this gives me back:
5.6.1804
but I just want the first number
bash shell-script shell
add a comment |
cat /etc/redhat-release
return:
CentOS Linux release 5.6.1804 (Core)
how do I select the first number I've only tried
cat /etc/redhat-release | awk '{print $4}'
and this gives me back:
5.6.1804
but I just want the first number
bash shell-script shell
add a comment |
cat /etc/redhat-release
return:
CentOS Linux release 5.6.1804 (Core)
how do I select the first number I've only tried
cat /etc/redhat-release | awk '{print $4}'
and this gives me back:
5.6.1804
but I just want the first number
bash shell-script shell
cat /etc/redhat-release
return:
CentOS Linux release 5.6.1804 (Core)
how do I select the first number I've only tried
cat /etc/redhat-release | awk '{print $4}'
and this gives me back:
5.6.1804
but I just want the first number
bash shell-script shell
bash shell-script shell
edited Jan 23 at 20:57
msp9011
4,27344065
4,27344065
asked Jan 23 at 20:34
ortigaortiga
83
83
add a comment |
add a comment |
6 Answers
6
active
oldest
votes
$ echo 'CentOS Linux release 5.6.1804 (Core)'|awk '{print $4}'|awk -F '.' '{print $1}'
5
Need I say more?
perfect thanks..
– ortiga
Jan 23 at 20:46
@ortiga Don't forget to select one answer you like the most and accept it. Personally, I would select the lsb_release answer, but my answer is closest to what you originally did.
– juhist
Jan 23 at 20:59
add a comment |
If your CentOS machine has redhat-lsb
or redhat-lsb-core
installed:
lsb_release -sr | cut -d '.' -f 1
This would get the release version (only) using the lsb_release
command and then cut
out the bit before the first dot.
On a 16.04
Ubuntu machine:
$ lsb_release -sr | cut -d '.' -f 1
16
add a comment |
Using awk:
awk -F '[ .]' '{print $4}' /etc/redhat-release
Using sed:
sed -E 's/[ Aa-Zz]*([0-9]+).*/1/' /etc/redhat-release
Using grep:
grep -Eo ' [0-9]' /etc/redhat-release
There's also/etc/os-release
– Sammitch
Jan 25 at 0:28
add a comment |
There are so many ways, here is one of those:
cat /etc/redhat-release | cut -d " " -f4 | cut -d . -f1
The easier way would be using something that is prepared just for that:
[user@server]$ source /etc/os-release && echo $CENTOS_MANTISBT_PROJECT_VERSION
7
add a comment |
sed -Ee's/^.* ([0-9.]+) .*$/1/' /etc/redhat-release |cut -f1,1 -d.
Sed command extracts the whole version number (same as your AWK, so you could use that as well) and the second extracts the first field from that using '.' as the separator.
so you could also use:
awk '{print $4}' /etc/redhat-release |cut -f1,1 -d.
add a comment |
I would do something akin to this. On my RH7 box:
$ cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.5 (Maipo)
$ cut -f 7 -d " " /etc/redhat-release
7.5
$ cut -f 7 -d " " /etc/redhat-release | IFS=. read MAJOR MINOR RELEASE
$ echo $MAJOR $MINOR $RELEASE
7 5
$
Now you have all the components of the build in an env var to be referneced at you leisure. There are more sophisticated ways to get the original data, but I think that's beyond the scope of this question, which is just extracting the components of a dotted version string.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f496317%2fhow-to-select-a-number%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
$ echo 'CentOS Linux release 5.6.1804 (Core)'|awk '{print $4}'|awk -F '.' '{print $1}'
5
Need I say more?
perfect thanks..
– ortiga
Jan 23 at 20:46
@ortiga Don't forget to select one answer you like the most and accept it. Personally, I would select the lsb_release answer, but my answer is closest to what you originally did.
– juhist
Jan 23 at 20:59
add a comment |
$ echo 'CentOS Linux release 5.6.1804 (Core)'|awk '{print $4}'|awk -F '.' '{print $1}'
5
Need I say more?
perfect thanks..
– ortiga
Jan 23 at 20:46
@ortiga Don't forget to select one answer you like the most and accept it. Personally, I would select the lsb_release answer, but my answer is closest to what you originally did.
– juhist
Jan 23 at 20:59
add a comment |
$ echo 'CentOS Linux release 5.6.1804 (Core)'|awk '{print $4}'|awk -F '.' '{print $1}'
5
Need I say more?
$ echo 'CentOS Linux release 5.6.1804 (Core)'|awk '{print $4}'|awk -F '.' '{print $1}'
5
Need I say more?
answered Jan 23 at 20:38
juhistjuhist
1333
1333
perfect thanks..
– ortiga
Jan 23 at 20:46
@ortiga Don't forget to select one answer you like the most and accept it. Personally, I would select the lsb_release answer, but my answer is closest to what you originally did.
– juhist
Jan 23 at 20:59
add a comment |
perfect thanks..
– ortiga
Jan 23 at 20:46
@ortiga Don't forget to select one answer you like the most and accept it. Personally, I would select the lsb_release answer, but my answer is closest to what you originally did.
– juhist
Jan 23 at 20:59
perfect thanks..
– ortiga
Jan 23 at 20:46
perfect thanks..
– ortiga
Jan 23 at 20:46
@ortiga Don't forget to select one answer you like the most and accept it. Personally, I would select the lsb_release answer, but my answer is closest to what you originally did.
– juhist
Jan 23 at 20:59
@ortiga Don't forget to select one answer you like the most and accept it. Personally, I would select the lsb_release answer, but my answer is closest to what you originally did.
– juhist
Jan 23 at 20:59
add a comment |
If your CentOS machine has redhat-lsb
or redhat-lsb-core
installed:
lsb_release -sr | cut -d '.' -f 1
This would get the release version (only) using the lsb_release
command and then cut
out the bit before the first dot.
On a 16.04
Ubuntu machine:
$ lsb_release -sr | cut -d '.' -f 1
16
add a comment |
If your CentOS machine has redhat-lsb
or redhat-lsb-core
installed:
lsb_release -sr | cut -d '.' -f 1
This would get the release version (only) using the lsb_release
command and then cut
out the bit before the first dot.
On a 16.04
Ubuntu machine:
$ lsb_release -sr | cut -d '.' -f 1
16
add a comment |
If your CentOS machine has redhat-lsb
or redhat-lsb-core
installed:
lsb_release -sr | cut -d '.' -f 1
This would get the release version (only) using the lsb_release
command and then cut
out the bit before the first dot.
On a 16.04
Ubuntu machine:
$ lsb_release -sr | cut -d '.' -f 1
16
If your CentOS machine has redhat-lsb
or redhat-lsb-core
installed:
lsb_release -sr | cut -d '.' -f 1
This would get the release version (only) using the lsb_release
command and then cut
out the bit before the first dot.
On a 16.04
Ubuntu machine:
$ lsb_release -sr | cut -d '.' -f 1
16
answered Jan 23 at 20:40
KusalanandaKusalananda
127k16240395
127k16240395
add a comment |
add a comment |
Using awk:
awk -F '[ .]' '{print $4}' /etc/redhat-release
Using sed:
sed -E 's/[ Aa-Zz]*([0-9]+).*/1/' /etc/redhat-release
Using grep:
grep -Eo ' [0-9]' /etc/redhat-release
There's also/etc/os-release
– Sammitch
Jan 25 at 0:28
add a comment |
Using awk:
awk -F '[ .]' '{print $4}' /etc/redhat-release
Using sed:
sed -E 's/[ Aa-Zz]*([0-9]+).*/1/' /etc/redhat-release
Using grep:
grep -Eo ' [0-9]' /etc/redhat-release
There's also/etc/os-release
– Sammitch
Jan 25 at 0:28
add a comment |
Using awk:
awk -F '[ .]' '{print $4}' /etc/redhat-release
Using sed:
sed -E 's/[ Aa-Zz]*([0-9]+).*/1/' /etc/redhat-release
Using grep:
grep -Eo ' [0-9]' /etc/redhat-release
Using awk:
awk -F '[ .]' '{print $4}' /etc/redhat-release
Using sed:
sed -E 's/[ Aa-Zz]*([0-9]+).*/1/' /etc/redhat-release
Using grep:
grep -Eo ' [0-9]' /etc/redhat-release
edited Jan 23 at 20:50
answered Jan 23 at 20:41
msp9011msp9011
4,27344065
4,27344065
There's also/etc/os-release
– Sammitch
Jan 25 at 0:28
add a comment |
There's also/etc/os-release
– Sammitch
Jan 25 at 0:28
There's also
/etc/os-release
– Sammitch
Jan 25 at 0:28
There's also
/etc/os-release
– Sammitch
Jan 25 at 0:28
add a comment |
There are so many ways, here is one of those:
cat /etc/redhat-release | cut -d " " -f4 | cut -d . -f1
The easier way would be using something that is prepared just for that:
[user@server]$ source /etc/os-release && echo $CENTOS_MANTISBT_PROJECT_VERSION
7
add a comment |
There are so many ways, here is one of those:
cat /etc/redhat-release | cut -d " " -f4 | cut -d . -f1
The easier way would be using something that is prepared just for that:
[user@server]$ source /etc/os-release && echo $CENTOS_MANTISBT_PROJECT_VERSION
7
add a comment |
There are so many ways, here is one of those:
cat /etc/redhat-release | cut -d " " -f4 | cut -d . -f1
The easier way would be using something that is prepared just for that:
[user@server]$ source /etc/os-release && echo $CENTOS_MANTISBT_PROJECT_VERSION
7
There are so many ways, here is one of those:
cat /etc/redhat-release | cut -d " " -f4 | cut -d . -f1
The easier way would be using something that is prepared just for that:
[user@server]$ source /etc/os-release && echo $CENTOS_MANTISBT_PROJECT_VERSION
7
answered Jan 23 at 20:39
Dmitriy KupchDmitriy Kupch
1012
1012
add a comment |
add a comment |
sed -Ee's/^.* ([0-9.]+) .*$/1/' /etc/redhat-release |cut -f1,1 -d.
Sed command extracts the whole version number (same as your AWK, so you could use that as well) and the second extracts the first field from that using '.' as the separator.
so you could also use:
awk '{print $4}' /etc/redhat-release |cut -f1,1 -d.
add a comment |
sed -Ee's/^.* ([0-9.]+) .*$/1/' /etc/redhat-release |cut -f1,1 -d.
Sed command extracts the whole version number (same as your AWK, so you could use that as well) and the second extracts the first field from that using '.' as the separator.
so you could also use:
awk '{print $4}' /etc/redhat-release |cut -f1,1 -d.
add a comment |
sed -Ee's/^.* ([0-9.]+) .*$/1/' /etc/redhat-release |cut -f1,1 -d.
Sed command extracts the whole version number (same as your AWK, so you could use that as well) and the second extracts the first field from that using '.' as the separator.
so you could also use:
awk '{print $4}' /etc/redhat-release |cut -f1,1 -d.
sed -Ee's/^.* ([0-9.]+) .*$/1/' /etc/redhat-release |cut -f1,1 -d.
Sed command extracts the whole version number (same as your AWK, so you could use that as well) and the second extracts the first field from that using '.' as the separator.
so you could also use:
awk '{print $4}' /etc/redhat-release |cut -f1,1 -d.
answered Jan 23 at 20:46
user55614user55614
1
1
add a comment |
add a comment |
I would do something akin to this. On my RH7 box:
$ cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.5 (Maipo)
$ cut -f 7 -d " " /etc/redhat-release
7.5
$ cut -f 7 -d " " /etc/redhat-release | IFS=. read MAJOR MINOR RELEASE
$ echo $MAJOR $MINOR $RELEASE
7 5
$
Now you have all the components of the build in an env var to be referneced at you leisure. There are more sophisticated ways to get the original data, but I think that's beyond the scope of this question, which is just extracting the components of a dotted version string.
add a comment |
I would do something akin to this. On my RH7 box:
$ cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.5 (Maipo)
$ cut -f 7 -d " " /etc/redhat-release
7.5
$ cut -f 7 -d " " /etc/redhat-release | IFS=. read MAJOR MINOR RELEASE
$ echo $MAJOR $MINOR $RELEASE
7 5
$
Now you have all the components of the build in an env var to be referneced at you leisure. There are more sophisticated ways to get the original data, but I think that's beyond the scope of this question, which is just extracting the components of a dotted version string.
add a comment |
I would do something akin to this. On my RH7 box:
$ cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.5 (Maipo)
$ cut -f 7 -d " " /etc/redhat-release
7.5
$ cut -f 7 -d " " /etc/redhat-release | IFS=. read MAJOR MINOR RELEASE
$ echo $MAJOR $MINOR $RELEASE
7 5
$
Now you have all the components of the build in an env var to be referneced at you leisure. There are more sophisticated ways to get the original data, but I think that's beyond the scope of this question, which is just extracting the components of a dotted version string.
I would do something akin to this. On my RH7 box:
$ cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.5 (Maipo)
$ cut -f 7 -d " " /etc/redhat-release
7.5
$ cut -f 7 -d " " /etc/redhat-release | IFS=. read MAJOR MINOR RELEASE
$ echo $MAJOR $MINOR $RELEASE
7 5
$
Now you have all the components of the build in an env var to be referneced at you leisure. There are more sophisticated ways to get the original data, but I think that's beyond the scope of this question, which is just extracting the components of a dotted version string.
answered Jan 23 at 21:54
GarethHumphriesAccGarethHumphriesAcc
1613
1613
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f496317%2fhow-to-select-a-number%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown