3

I have the following bogus data:

Dominik Dryja|4111 2386 0873 0189|0315
Laivonen Eero|5111 0620 0750 8041|0813
Jukka Valimaa|5111 6500 0489 0035|0415
Rafael Diaz de Leon|4111 3036 6209 4796|0516
Mr Jonathan Bird|4111 6150 0291 7415|0215
ERRANTE VINCENZO|4222 6111 0038 6639|0114
YOSHIO MOTOKI|5222 3200 0374 7129|0513
I. A. VLACHOGIANNIS|4333 0115 6936 2003|0315
Soumya Kanti Deb|4333 0590 0165 4877|1019
WU KE ZHAN|5444 8213 7236 0431|0716

I try to strip the space ONLY from the digit number to look like this:

Dominik Dryja|4111238608730189|0315
Laivonen Eero|5111062007508041|0813
Jukka Valimaa|5111650004890035|0415
Rafael Diaz de Leon|4111303662094796|0516
Mr Jonathan Bird|4111615002917415|0215
ERRANTE VINCENZO|4222611100386639|0114
YOSHIO MOTOKI|5222320003747129|0513
I. A. VLACHOGIANNIS|4333011569362003|0315
Soumya Kanti Deb|4333059001654877|1019
WU KE ZHAN|5444821372360431|0716

Tried sed -r '#|([0-9]{4})\ ([0-9]{4})\ ([0-9]{4})\ ([0-9]{4})|#\1\2\3\4#g' for some reason without success. Any idea where I'm mistaken?

Thanks!

2 Answers 2

2

You can simplify your sed:

sed 's/\([0-9]\{4\}\) /\1/g' inFile
1

Assuming there's always a single space between numbers:

sed 's/\([0-9]\) \([0-9]\)/\1\2/g'

Works with your example. The code is simple - remove all single spaces if they happen between two digits.

4
  • Yes, it works but my digit pattern is "|dddd dddd dddd dddd|", your answer will remove the single space between "dd dd" too, and that I don't want.
    – bsteo
    Apr 26, 2013 at 7:48
  • 1
    Your example doesn't have such patterns, so I thought any space between digits should be removed.
    – aragaer
    Apr 26, 2013 at 8:29
  • How doesn't it? "|4111 6150 0291 7415|"
    – bsteo
    Apr 26, 2013 at 9:39
  • 1
    It doesn't have patterns where spaces should be kept.
    – aragaer
    Apr 26, 2013 at 9:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.