I have the below file which I pass to a perl code. Usually the format is that 6th Field of the line starting with FILE is a number. But in some cases, the number falls to the next line. The number is important to me. I need to bring the number by replacing "\" to the line starting with FILE. I tried chomp and all. But didnot work.

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

Below is the latest code I tried.
#! /usr/bin/Perl my $file1 = "file.txt"; open(INOUT1,"<", $file1) or die "cant open output file "; + foreach $line(<INOUT1>) { #chomp $line; if ($line =~ /\\/){ $line =~ s/\\\n//; if ($line =~ /\s+/){ $line =~ s/\s+//; push(@newlines,$line); }} } foreach $linw(@newlines){ if ($linw =~ m/^FILE /) { print $linw,"\n"; next; } }

Output I need is

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


In reply to 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.