in reply to problem with splitting file on whitespace: how to circumvent inconsistent formatting through file

This should work:

print join "\t", split ' *(?=[^0-9,])', '15,567 -25,324-45,234';; 15,567 -25,324 -45,234

As a one-liner:

perl -nle"print join qq[\t], split ' *(?=[^0-9,])'" < bad.file > good. +file

Don't forget to swap 's and "s if you're on *nix.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice. Not understood.
  • Comment on Re: problem with splitting file on whitespace: how to circumvent inconsistent formatting through file
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: problem with splitting file on whitespace: how to circumvent inconsistent formatting through file
by angela2 (Sexton) on Jul 04, 2016 at 14:02 UTC
    I don't know how I managed to get it wrong but after an hour of trying I made them both work :) Thank you very much!