#!/usr/bin/perl use strict; my $firstrow = 1; my @positions = (); while ( defined( my $line = <DATA> ) ) { if ( $firstrow ) { # process first row $firstrow = 0; my $startpos = 0; while ( ( my $nextpos = index( $line, '<', $startpos ) ) >= 0 +) { push( @positions, $nextpos ); $startpos = $nextpos + 1; } next; } # extract columns according to the calculated @positions array my @columns = (); for ( my $i = 0; $i < @positions; $i++ ) { my ( $start, $finish ) = ( $positions[$i], $positions[$i+1] ); if ( defined( $finish ) ) { push( @columns, substr( $line, $start, $finish - $start ) +); } else { push( @columns, substr( $line, $start ) ); } } print( "\"" . join( "\",\"", @columns ) . "\"\n" ); } __DATA__ <S> <C> <C> <C> <C +> <C> <C> <C> <C> <C> <C> <C> ACACIA RESH CORP ACACIA TCH COM 003881307 110,725 1 +,875,000 SHS SHARED-OTHER 1,2,3 1,875,000 0 0
This produces the following output:
"ACACIA RESH CORP ","ACACIA TCH COM ","003881307 "," 11 +0,725 "," 1,875,000"," SHS"," "," SHARED-OTHER"," 1,2,3 "," + 1,875,000"," 0 "," 0"
In reply to Re: How to find start position of each column
by monarch
in thread How to find start position of each column
by Gangabass
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |