vivek.vivek has asked for the wisdom of the Perl Monks concerning the following question:
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
Back to
Seekers of Perl Wisdom