Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Using perl's -n and -l switches on the shebang line of a short script in conjuction with a few global variables and a BEGIN block make this kind of processing the epitomy of the perl 'backronym' Practical Extraction & Reporting Language. Real bread&butter stuff.

You will probably need to strengthen the regexes to suit your data, and you may need to adjust the format used for the printf somewhat, but this should get you some of the way there.

The only slightly trick part if the $headerProcessed var and the use of eof which isn't very well described.

Usage: yourscriptname files* > unified.log

If your on a platform that expands wildcard arguments on the command line, the comment out the first line of the BEGIN block. The second line will list the expanded wilcards to STDERR which may or may not be useful in use.

#! perl -nlw use strict; use vars qw[$format $headerProcessed $author $MRnumber $releaseNo $fea +tureNo $featureName $filename $date]; BEGIN{ @ARGV = map{ glob } @ARGV; print STDERR "Processing files @ARGV"; $format = '%-25s ' x 9 . $/; $headerProcessed = 0; printf $format, 'File Name,', 'Author(Core ID),', 'Date (MM/DD/YEAR),', 'Release No.,', 'MR No.,', 'Feature No.,', 'Feature Name,', 'Paragrah No.,', 'Requirement No.'; } $headerProcessed = 0 if eof; unless ( $headerProcessed ) { $author = $1 . ',' if m[^Author \(Core ID\) : (.*$)]; $MRnumber = $1 . ',' if m[^MR Number : (.*$)]; $releaseNo = $1 . ',' if m[^Release Number : (.*$)]; ($featureNo, $featureName) = ($1 . ',', $2 . ',') if m[^Feature : (.*?) : (. +*$)]; $filename = $1 . ',' if m[^File Name : (.*$)]; $date = $1 . ',' if m[^Modification Date : (.*$)]; $headerProcessed = 1 if m[^Paragraph Number Requiremen +t Number Last Modified Release$]; } else { printf $format, $filename, $author, $date, $releaseNo, $MRnumber, $featureNo, +$featureName, (split/\s+/)[0,1]; } __END__ C:\test>244122 244122.dat? Processing files 244122.dat1 244122.dat2 File Name, Author(Core ID), Date (MM/DD/YEAR), + Release No., MR No., Feature N +o., Feature Name, Paragrah No., +Requirement No. cpsfs_sdu_setup.fm, az1287, 10/24/2001, + 16.1, sc018498.14, na, + Add IP, SDUSETUP-SDU-249 +CPSFS-SDUSETUP-224 cpsfs_sdu_setup.fm, bz1287, 10/24/2001, + 16.1, sc018498.14, na, + Add IP, SDUSETUP-SDU-249 +CPSFS-SDUSETUP-224 C:\test>

Examine what is said, not who speaks.
1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
3) Any sufficiently advanced technology is indistinguishable from magic.
Arthur C. Clarke.

In reply to Re: Converting text file to CSV format by BrowserUk
in thread Converting text file to CSV format by pelp

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



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-24 07:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found