This is 4 sed expressions; long but simple
It adds an excess of leading zeroes, and then trims the numbers to 3 and 4 long for the left and right sides respectively.
It is hard to construct something like this in a single line, but it is quite easy when it is laid out over many lines as shown in the last code section...
printf may be a solution, but it is not be as simple as I first thought, because of negative numbers, ie. your requirement is that all the negative numbers have the same number of digits as the positive numbers..
...so I'm throwing in this sed method because it does work, but there may be more simple solutions...
sed -r -e "s/^([0-9]+)( : )([0-9]+)( = )(-)?([0-9]+)( )/00\1\200\3\4\500\6\7/" -e "s/0*([0-9][0-9][0-9])( : )0*([0-9][0-9][0-9])( = )(-)?0*([0-9][0-9][0-9])( )/\1\2\3\4\5\6\7/" -e "s/( )([0-9]+)( : )([0-9]+)( = )(-)?([0-9]+)( .)$/\1000\2\3000\4\5\6000\7\8/" -e "s/( )0*([0-9][0-9][0-9][0-9])( : )0*([0-9][0-9][0-9][0-9])( = )(-)?0*([0-9][0-9][0-9][0-9])( .)$/\1\2\3\4\5\6\7\8/" \
<<'EOF'
261 : 261 = 0 | 1192 : 1184 = 8 |
283 : 283 = 0 | 666 : 659 = 7 |
267 : 267 = 0 | 631 : 620 = 11 |
283 : 283 = 0 | 787 : 781 = 6 |
278 : 279 = -1 | 963 : 957 = 6 |
278 : 279 = -1 | 963 : 954 = -1 |
EOF
Here is the output
261 : 261 = 000 | 1192 : 1184 = 0008 |
283 : 283 = 000 | 0666 : 0659 = 0007 |
267 : 267 = 000 | 0631 : 0620 = 0011 |
283 : 283 = 000 | 0787 : 0781 = 0006 |
278 : 279 = -001 | 0963 : 0957 = 0006 |
278 : 279 = -001 | 0963 : 0954 = -0001 |
Here is a more readable version of the sed expressions.
sed -r \
-e "s/^\
([0-9]+)( : )\
([0-9]+)( = )(-)?\
([0-9]+)( )\
/00\1\200\3\4\500\6\7/" \
-e "s/\
0*([0-9][0-9][0-9])( : )\
0*([0-9][0-9][0-9])( = )(-)?\
0*([0-9][0-9][0-9])( )\
/\1\2\3\4\5\6\7/" \
-e "s/( )\
([0-9]+)( : )\
([0-9]+)( = )(-)?\
([0-9]+)( .)$\
/\1000\2\3000\4\5\6000\7\8/" \
-e "s/( )\
0*([0-9][0-9][0-9][0-9])( : )\
0*([0-9][0-9][0-9][0-9])( = )(-)?\
0*([0-9][0-9][0-9][0-9])( .)$\
/\1\2\3\4\5\6\7\8/" \