If you don’t mind using a different command, and don’t mind having it formatted in json, you can output qstat to json and use jq to process it.
This is what I used to get unique users in a queue:
[vstumpf@shecil ~]$ qstat
Job id Name User Time Use S Queue
---------------- ---------------- ---------------- -------- - -----
1000066.shecil STDIN pbsuser 00:00:00 R workq
1000067.shecil STDIN vstumpf 00:00:00 R workq
1000068.shecil STDIN vstumpf 00:00:00 R workq
1000069.shecil STDIN vstumpf 00:00:00 R workq
1000070.shecil STDIN pbsuser 0 Q workq
1000071.shecil STDIN pbsuser1 0 Q workq
1000073.shecil STDIN pbsuser2 0 Q exprq
[vstumpf@shecil ~]$ qstat -f -Fjson | jq '.Jobs | map(select(.queue == "workq") | .euser) | unique'
[
"pbsuser",
"pbsuser1",
"vstumpf"
]
[vstumpf@shecil ~]$ qstat -f -Fjson | jq '.Jobs | map(select(.queue == "exprq") | .euser) | unique'
[
"pbsuser2"
]
FWIW, before there was the option for JSON output, we used the option when building qstat to enable a built-in TCL interpreter. With that, you could supply TCL scripts that qstat would use to format output. For example, here is our standard qstat output:
$ qstat -a
pbspl233b.nas.nasa.gov: Wed Oct 30 12:04:37 2019
Server reports 6 jobs total (T:0 Q:0 H:5 W:0 R:1 E:0 B:0)
Host CPUs Tasks Jobs Info
----------- ----- ----- ---- -------------------
1116 hosts 13392 0 -- wes
34 hosts 84 0 -- wes down
379 hosts 4548 4548 -- wes in-use
227 hosts 648 0 -- wes offline
18 hosts 216 0 -- wes q=diags
r733i2n3 0 0 0 wes q=diags offline
r789i2n13 0 0 0 wes q=diags offline
16 hosts 96 0 -- wes {offline down}
Req'd Elap Rem
SeqNo User Queue Jobname CPUs Nds wallt Ss wallt Eff wallt
------ -------- ----- ---------- ---- --- ----- -- ----- --- -----
633184 userfred long HLSchem30m 4548 379 16:00 R 04:40 93% 11:20
633153 usertom long merwesC64 6 6 02:40 Hs -- -- 02:40
633154 usertom long merwesC128 12 12 01:20 Hs -- -- 01:20
633155 usertom long merwesC256 22 22 01:00 Hs -- -- 01:00
633156 usertom long merwesC512 43 43 01:00 Hs -- -- 01:00
633157 usertom long merwesC102 86 86 00:30 Hs -- -- 00:30