Skip to content

Instantly share code, notes, and snippets.

@mskrajnowski
Last active January 31, 2025 11:00
Show Gist options
  • Save mskrajnowski/c19f593c826b093b151e26e0e6177373 to your computer and use it in GitHub Desktop.
Save mskrajnowski/c19f593c826b093b151e26e0e6177373 to your computer and use it in GitHub Desktop.
sky show-gpus as CSV
#!/usr/bin/env bash
set -euo pipefail
sky show-gpus "$@" | awk '
BEGIN { skip = 1; skip_heading = 0 }
# skip lines until the first GPU table heading
skip && /^GPU / { skip = 0; }
skip { next; }
# skip empty lines
/^\s*$/ { next; }
# skip following GPU table headings
skip_heading && /^GPU / { next; }
/^GPU / { skip_heading = 1 }
# convert line to CSV
{
gsub(/ {2,}/, ",");
gsub(/\$ /, "");
while (gsub(/,\-,/, ",,")) {};
gsub(/,\s*$/, "");
print;
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment