Skip to content

Instantly share code, notes, and snippets.

@briantjacobs
Created November 24, 2015 19:43
Show Gist options
  • Select an option

  • Save briantjacobs/7753bf850ca5e39be409 to your computer and use it in GitHub Desktop.

Select an option

Save briantjacobs/7753bf850ca5e39be409 to your computer and use it in GitHub Desktop.
Parse YAML from bash with sed and awk.
@phiarchitect
Copy link

this is ingenious.

@chrisbergeron
Copy link

How can I convert the prefix to uppercase (toupper) using printf in awk? Sorry, awk is not my strong suit.
I tried using a bash builtin ${string^^} but it doesn't work within the awk print.

@sf-thomasblanchard
Copy link

sf-thomasblanchard commented Jan 16, 2023

How can I convert the prefix to uppercase (toupper) using printf in awk? Sorry, awk is not my strong suit. I tried using a bash builtin ${string^^} but it doesn't work within the awk print.

Suggestion 1: use awk's toupper (respect. tolower) functions

printf("%s%s%s=(\"%s\")\n", "'"$prefix"'",vn, toupper($2), $3);

Suggestion 2: create a separate prefix variable all uppercase (not tested, ymmv)

local prefix=${2}
local prefix_upper=${2^^}

[...]
printf("%s%s%s=(\"%s\")\n", "'"$prefix_upper"'",vn, $2, $3);

@chrisbergeron
Copy link

The first suggestion works. The second didn't (macos awk). Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment