To limit the number of labels returned, you can use the -m
option:
p4 labels -m 1 -e 'your pattern'
This will only return a single label. Also of note, many of the p4 commands will take the -m
parameter to control the number of results that are returned. One more thing: the -E
version of the pattern parameter makes the filter pattern case insensitive if you desire/need that.
Reference: http://www.perforce.com/perforce/doc.current/manuals/cmdref/labels.html
If the p4 labels command isn't getting you what you desire, I would suggest taking a look at the Perl, Python and Ruby APIs provided by perforce - these are all supported libraries by the staff at Perforce, and quite capable of interfacing your custom code needs.
http://www.perforce.com/product/components/apis