fork download
  1. #!/bin/bash
  2. g='XABC
  3. XA-BC8D
  4. X-ABC
  5. XB72D-
  6. X123
  7. XAB
  8. XABC-123
  9. XA--BC'
  10. awk '/^[Xx][[:upper:][:digit:]-]{3,6}$/ && /.[[:upper:]]/ {val=$0; sub("-","",val); if (val ~ /^[Xx][[:upper:][:digit:]]+$/) {print $0;}}' <<< "$g"
  11.  
Success #stdin #stdout 0s 4648KB
stdin
Standard input is empty
stdout
XABC
XA-BC8D
X-ABC
XB72D-