Skip to content

Instantly share code, notes, and snippets.

@jxu
Created October 18, 2019 21:38
Show Gist options
  • Save jxu/87ce3142ea91c051e6fb1ef5c257ced8 to your computer and use it in GitHub Desktop.
Save jxu/87ce3142ea91c051e6fb1ef5c257ced8 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Executing grep every time is a little slow, but bash regex doesn't support
# lazy evaluation and it's not worth rewriting...
IFS='' # Preserve whitespace for read
while read p; do # Read /boot/grub/grub.cfg line by line
LINE_REGEX=`echo $p | grep -Po "menuentry ['\"]\K.+?(?=['\"])"`
if [ "$LINE_REGEX" ]; then
# Submenu lines begin with a tab, so lazy method is to check for that
if [ ${p::1} = ' ' ]; then
echo " $LINE_REGEX"
else
echo $LINE_REGEX
fi
fi
done < /boot/grub/grub.cfg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment