If the string is of the pattern XxxXyzAbc...
The expected out put from sed has to be Xxx Xyz Abc ...
eg: if the string is QcfEfQfs, then the expected output is Qcf Ef Efs.
If i try to substitute the pattern [a-z][A-Z] with space then the sed will replace the character or pattern with space, like Qc f fs.
Is there any way to insert space in between without replacing the pattern ?.
Kindly help. Thanks.
This does it:
$ echo "QcfEfQfs" | sed 's/[A-Z]/ &/g'
Qcf Ef Qfs
But can leave a space at the front, the version below uses another sed rule to trim a leading space:
$ echo "ElephantsGreatBigDirtyFeet" | sed 's/[A-Z]/ &/g;s/^ //'
Elephants Great Big Dirty Feet
And a little more complex again but preserves space in from of existing string (if present):
$ echo "EveryGoodBoyDeservesFruit" | sed 's/\([a-z]\)\([A-Z]\)/\1 \2/g'
Every Good Boy Deserves Fruit