foo bar baz booz qaaz abc foo bar baz booz qaaz abc 123 foo bar baz booz qaaz abcSHOULD output to
foo bar baz booz qaaz abc foo bar baz booz qaaz abc 123 foo bar baz booz qaaz abcI read the file twice. The first time to get max position of each TAB stop for each line that I put into $max array. If a line has a Nth TAB stop bigger than any previous line then $max[$max_tab] is augmented
print substr("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t", 0, ($max[$max_tab++] +- $+[0]) / 8), substr($_, $-[0], $+[0]);
foobar babaz booz qabooz qaaz abcqaaz abcabc foobar baz baz booz qabooz qaaz abc 123qaaz abc 123abc 123 123 foobar bazbaz booz qaabooz qaaz abcqaaz abcabc
and get the right indexesprint $-[0], ' ', $+[0], ' ';
3 4 7 9 12 13 17 19 23 26 3 5 8 9 12 14 18 19 23 24 27 28 3 5 8 10 13 15 19 20 24 26
https://www.geeksforgeeks.org/perl-substr-function/ https://perldoc.perl.org/functions/substr https://www.tutorialspoint.com/perl/perl_substr.htm https://squareperl.com/en/function/substrand give the right arguements i m trying to figure out what s wrong
$valid_line==0; $nbr_line=$ARGV[1]; # format the first digit @_[0], length @_[1] wide with leading 0s sub format { return substr("00000000", 0, (@_[1] - length(@_[0]))) . @_[0]; } open(F0, $ARGV[0]); while(<F0>) { if (/[a-zA-Z0-9]/) { $valid_line++; $max_tab = 0; while (/\t+/g) { # print $-[0], ' ', $+[0], ' '; $max[$max_tab] = $+[0] if $max[$max_tab] < $+[0] ;$max_tab +++; } # print "\n"; $nbr_tab = $max_tab if $nbr_tab < $max_tab; } } $max_line=$nbr_line+$valid_line; seek F0,0,0; while(<F0>) { s/\r//;chop; $max_tab = 0; while (/[^\t]+/g) { print substr("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t", 0, ($max[$ma +x_tab++] - $+[0]) / 8), substr($_, $-[0], $+[0]); } print "\n"; } close F0;
In reply to misalined TABs using substr,LAST_MATCH_START/END,regex by perl_boy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |