A more accurate pattern match — one with fewer false matches of strings that are not in the XxxYyyZzz format — is:
sed 's/\([AZ][az][az]*\)\([AZ][az][az]*\)\([AZ][az][az]*\)/\1 \2 \3/'
Consider the inputs:
XxxYyyZzz xxxYyyZzz X xY yZ z
Another answer that I see will insert spaces in all lines - when it should only change the first line.
Updated to allow QcfEfEfs example - it is not clear from the question how many valid letters per line are valid. It can be 1 or 2; or it can be 1 or more - use * allows 1 or more; otherwise use \{1,2\} for 1 or 2.
source share