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

++$anecdote ne $data



In reply to Re: Perl Newline Help by ww
in thread Perl Newline Help by vivek.vivek

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.