Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help Creating Script to Parse a Flat File

Status
Not open for further replies.

batcater98

Programmer
May 30, 2007
7
US
I having troubles with the different seperators in this one and just picking out the lines I want keyed from the .dat filename. I basically have an autogenerated flat file that is an export of a directory structure. I want to parse through the flat file and pull values from specific lines that contain a file name with the extention of .dat. From that I want to collect the Date-Time, Size, and portion of the filename. And skip the rest.

.Example Flat File.

Volume in drive E is NEW Data
Volume Serial Number is 901D-960F

Directory of E:\My_DATA\LooK_Here\Year_2008\02_21_08

02/20/2008 12:52 PM <DIR> .
02/20/2008 12:52 PM <DIR> ..
02/02/2008 11:35 AM 851,744 01ID0801.dat
02/05/2008 11:35 AM 61 01ID0801.sta
02/09/2008 11:36 AM 299,216 01ID0823.dat
02/09/2008 11:36 AM 61 01ID0823.sta
02/10/2008 11:36 AM 373,018 01ID0827.dat
02/10/2008 11:36 AM 61 01ID0827.sta
02/11/2008 11:37 AM 49,258 01ID0855.dat
02/11/2008 11:37 AM 61 01ID0855.sta
02/15/2008 11:37 AM 427,803 01ID0861.dat
02/15/2008 11:37 AM 61 01ID0861.sta
02/18/2008 11:37 AM 282,035 01ID0865.dat
02/18/2008 11:38 AM 61 01ID0865.sta
1604 File(s) 386,639,292 bytes
2 Dir(s) 78,292,127,744 bytes free

.End Flat File Example.

.Output Desired.
Record 1
Date-Time = 02/02/2008 11:35 AM
Size = 851,744
Name = 0801 (This is always 4 characters to left of the .)
Record 2
Date-Time = 02/09/2008 11:36 AM
Size = 299,216
Name = 0823 (This is always 4 characters to left of the .)
ect....

Thanks for any help on this.
 
post the code you have written so far to try and accomplish your goal.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Regular expressions look for patterns, and so should you. All the lines you want end with .dat So
Code:
while (<>) {
   print if (/\.dat$/i);
}
should get you started. Then it's just a simple case of splitting the data up.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
($date, $time, $meridien, $size, $name)=split (/\s+/, $_);

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top