Just another (ugly) way to tackle this (omitting print of unchanged "FILE..." lines and all data:)
#!/usr/bin/Perl use strict; use warnings; use 5.018; # 1106853.pl # assumes that the number to be moved up has > 1 digit and that # un-movable lines begin with not_more_than 0 or 1 digits before a non +-digit char. my ($line, @newlines, $linw, $line_may_need_a_fix); my @arr = <DATA>; START: for (my $i=0; $i < @arr; $i++) { $line = $arr[$i]; if ( $line =~ /\d{4} \\$/ ) { $line_may_need_a_fix = $line; next START; } elsif ( $line_may_need_a_fix && ($line =~ /^([0123456789]{2,4})/ +) ) { my $nums = $1; chomp $line_may_need_a_fix; $line_may_need_a_fix =~ s/\\$//; my $fixedLine = $line_may_need_a_fix . $nums; # Left as an ex +ercise: # removing $num +s from $line push(@newlines,$fixedLine); # Likewise, capture of $line an +d un-movables } $line_may_need_a_fix = ''; } foreach $linw(@newlines){ if ($linw =~ m/^FILE /) { print $linw,"\n"; next; } } __DATA__ FILE TEXT VAL 9999.999 08-jul-2014 \ 270 3E4497B6B8482ADED734 HDNDFLHWLEJHFL LKSNFLKN \ WKENFLWHFELHN UIEKEFJBKJFN FILE TEXT2 VAL 9999.999 16-may-2014 60 \ 8EC4B7367989D54F6D6C HSHFGFLALKHF KJAHEFKHAH\ YRNBFLJNELFN LQJFLKJWEF LKJFLKWJF FILE TEXT3 VAL 000.01 06-apr-2014 \ 1313 ABC3DEF XY77ZZ FILE TEXT4 VAL 213.7 05-feb-1013 95 \ 74nbfljaxlon lgggkjaxor blosqr4
Output:
FILE TEXT VAL 9999.999 08-jul-2014 270 FILE TEXT3 VAL 000.01 06-apr-2014 1313
In reply to Re: Perl Newline Help
by ww
in thread Perl Newline Help
by vivek.vivek
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |