On Mar 13, 2006, at 6:20 PM, chris h wrote:

I'm wondering if any of you data massagers out there have a BBEdit script or tool to transpose formatted text data -- to swap columns & rows.

The data set I have has about 1500 fields in each record. I need to get it into Excel, but Excel can only handle 256 columns, hence the need to transpose it as a text file before importing.

Right now the fields are comma-delimited, but could easily be tab- delimited if that matters.

If it's comma delimitated (not CSV, so no escaped commas),
you can use something like the following, saved in the
'Unix Filters' directory ... adjust the numbers as needed
for the correct output order (and remember -- it starts at
0, not 1)


#!/usr/bin/perl --

while ( my $line = <> ) {
    chomp $line;
    my @fields = split /,/, $line;

    # if you want to count starting at 1, change above to:
    # my @fields = (undef, split /,/, $line);

    print join ',', @fields[0..24,50..499,25..49,500..$#fields];
    print "\n";
}

__END__

-----
Joe Hourcle

--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <[EMAIL PROTECTED]>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
To unsubscribe, send mail to:  <[EMAIL PROTECTED]>

Reply via email to