Skip to content

Instantly share code, notes, and snippets.

@GavinRay97
Last active July 13, 2020 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GavinRay97/fcd2e7bb7dce9201fadec134a3348fc4 to your computer and use it in GitHub Desktop.
Save GavinRay97/fcd2e7bb7dce9201fadec134a3348fc4 to your computer and use it in GitHub Desktop.
Bash Regex with capture groups
#! /bin/bash
# VERSION NAME SOURCE STATUS DATABASE STATUS
# 1594317652188 - Not Present Present
# 1594317688377 - Not Present Present
# 1594320512973 - Not Present Present
# 1594320556497 - Not Present Present
function scan_entries_for_not_present() {
# timestamp name source status database status
regex="([[:digit:]]+)\s+(\w+|-)\s+(Present|Not Present)\s+(Present|Not Present)"
while IFS= read -r line; do
if [[ "$line" =~ $regex ]]; then
for group in "${BASH_REMATCH[@]}"; do
printf "%s\n" "$group"
done
else
printf "No match \n"
fi
done
}
hasura migrate status | scan_entries_for_not_present
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment