Skip to content
Advertisement

capturing words between double quotes in awk

I’m trying to print the name of my Linux distribution. The output of cat /etc/os-release for my distro is:

NAME="Arch Linux"
PRETTY_NAME="Arch Linux"
ID=arch
BUILD_ID=rolling
ANSI_COLOR="0;36"
HOME_URL="https://www.archlinux.org/"
DOCUMENTATION_URL="https://wiki.archlinux.org/"
SUPPORT_URL="https://bbs.archlinux.org/"
BUG_REPORT_URL="https://bugs.archlinux.org/"
LOGO=archlinux

Now I want to grab the Arch Linux from the second line. I used this command:

cat /etc/os-release | awk '/PRETTY_NAME=".+"/ {print $1}'

But this prints PRETTY_NAME="Arch

How can I grab the words (including space) from this line?

Advertisement

Answer

Setting the field delimiter to double quotes -F'"' to remove quotes from output.

 awk -F'"' '/^PRETTY_NAME=/{print $2}' /etc/os-release
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement