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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|