Dear Perl Monks,

I humbly seek your assistance and beg your patience. I have this huge file with more than a few hundreds of thousands of records which is from the output of tape archive of some sort. I do not have at all access to it to rerun it so as to reconfigure the output. I am stuck with what I got. The file is broken into multi-line columns of data. A new record is indicated by a listing in the NodeName column which is never more than one line in length unlike the other variables. BackupDate is always streaches 2 lines while FileName and PathName can be 1 or more lines in length. Please see a small example snippet:
Table ---------------------------------------------- NodeName FileName PathName BackupDate BD3101 bananaswi \breakfa 2007-03-06 ithapple st\fruit 14:02:31.000000 s.gif s\tree\ TP4223 chocolate \sweet\d 2006-02-28 caramelfu esserts\ 21:16:41.000000 dge.gif hersheys\ EO2123 tofuwith \organic\ 2007-07-16 peas.gif vegetable 13:55:06.000000 s\legumes\ ---------------------------------------------------
Desired Output Should be in a single line form but should be able to kept in straight columns. The total width of the output can be huge as long as each variable is of same maximum column width throughout without going into another line for each record. The output should be printed in the following order: NodeName FileName PathName BackupDate. Using the above listed example, the output I would expect from this would be:

-----------------------------------------------------------
BD3101 bananaswithapples.gif \breakfast\fruits\tree\ 2007-03-06 14:02:31.000000
TP4223 chocolatecarmelfudge.gif \sweet\desserts\hersheys\ 2006-02-28 21:16:41.000000
EO2123 tofuwithpeas.gif \organic\vegetables\legumes\ 2007-07-16 13:55:06.000000


The way I tackled this was to declare the position delimited variables (based upon the above table):
Column Position of Table NodeName =1->10 FileName =11->20 PathName =21->30 BackupDate =30->End of Line
Here is what I have written so far but I really do need help:
#!/usr/bin/perl -w use strict; { my $input =$ARGV[0]; #returns filename from command line my $nodename; my $filename; my $pathname; my $backupdate; my $textline; my $nochar =""; my $charposition; my $nextrecord; chomp $input; #strip the carriage return open (DATAFILE, "$input")|| die ("Can not open $input:!\n"); #access the file while (my $textline=<DATAFILE>) { chomp $textline; foreach my $textline { next if ($textline =~ /($charposition = m/({0}/)!= $no +char; else { $nodename = m/({0,9}/; $filename = m/({10,19}/; $pathname = m/({20,29}/; $backupdate = m/({30).*/; printf ("%s%s%s%s\n",$nodename, $filename, $backupdate, $pathname); } } close (DATAFILE); }
Thank you so very much again for all the PerlMonks who have been a real lifesaver!

In reply to MultiLine Tables into Variables by Knoperl

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.