Yes! You can use jq to extract and expand the GPU indices from the gres_detail field. Here’s how you can do it:
bashsqueue --job $SLURM_JOB_ID --json | jq -r '.jobs[0].gres_detail' | \ grep -oP 'IDX:\K[^)]+' | \ tr ',' '\n' | \ sed 's/-/,/g' | \ tr '\n' ',' | \ sed 's/,$//'
squeue --job $SLURM_JOB_ID --json | jq -r '.jobs[0].gres_detail'
Extracts the gres_detail field as a string.
grep -oP 'IDX:\K[^)]+'
Extracts the part after IDX: and before the closing parenthesis, e.g., 1-2,4.
tr ',' '\n'
Replaces commas with newlines to process each index range separately.
sed 's/-/,/g'
Replaces the hyphen in ranges like 1-2 with a comma, turning it into 1,2.
tr '\n' ','
Joins all indices with commas.
sed 's/,$//'
Removes the trailing comma.
For your example input:
text[ "gpu:b200:3(IDX:1-2,4)" ]
The output will be:
text1,2,4