I found this:
$> echo " 1234567890 " | sed -r ':L;s=\b([0-9]+)([0-9]{3})\b=\1,\2=g;t L'
1,234,567,890
source:
http://www.linuxquestions.org/questions/programming-9/format-numbers-using-bash-672031/#post3291347
So I was able to understand it a little by changing some stuff:
echo "1234567890" | sed -r ':L;s#([0-9]+)([0-9]{3})#\1,\2#g;t L'
I removed the backspace and changed the separator from "=" to "#"
I still don't see how it works. I read about labels, I understand that the "t L" commands tells it to jump to "L" label when successful. But If I understand it correctly, then the first group "([0-9]+)" should be getting the whole number (greedy).
I am puzzled. can anyone help me break it down so I can understand this better?
Thanks,
Daniel.