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

Hi angela2

I can see that you've already had some great responses - some more easily understood than others; so for posterity here are a couple of one-liners similar to what BrowserUk suggested here Re: problem with splitting file on whitespace: how to circumvent inconsistent formatting through file that also take into account tab delimited columns and numbers with decimal points.

one-liner to print all columns

perl -F"\s*(?=[^\d,\.])" -wanle "print qq[@F]" badfile.txt

one-liner to print column 1

perl -F"\s*(?=[^\d,\.])" -wanle "print $F[0]" badfile.txt

...use $F[n-1] to access column n, e.g. print $F[1] will print the value for column 2.

quick explanation of command-line flags


See perlrun for a more info as I have only scratched the surface...

Best Wishes,
shadowsong

  • 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 05, 2016 at 14:22 UTC
    This is good stuff, thanks!