how can I combine the following two awk commands into a single line:
awk -F= '$1=="ID" { print $2 ;}' /etc/*release && awk -F= '$1=="VERSION_ID" { print $2 ;}' /etc/*release | xargs
Im trying to get the linux distribution and os in a single line, in the format distribution version. For example: ubuntu20.04, rhel7.5
thanks in advance
CodePudding user response:
With bash
:
source /etc/os-release; echo "$ID $VERSION_ID"
CodePudding user response:
You can capture each part into a variable and then print them out once you have processed the file:
awk -F= '$1=="ID"{id=$2}$1=="VERSION_ID"{vid=$2}END{print id,vid}' /etc/*release
CodePudding user response:
I assume you don't want the quotes (as in your example), in that case:
awk -F '["=]' '$1=="ID" {printf("%s,",$3)} $1=="VERSION_ID" {printf("%s\n",$3)}' < /etc/*release