I have several text files that I need certain content parsed out of each.
What I need is to grab the data for each Note that is after the Body tag. Each file is going to have a different amount of data as well. Oh, and I also need to have the client name within this new data set. Each files notes are also in different orders.
So for example, for all 100+ files, I need to parse out the "Web Hosting Information" and put it into a spreadsheet format.
Here is a partial example of one of the textfiles ( I have stared out sensitive information)
My end goal is to be able to have ... for example all of the Web Hosting information from each file within one delimited text file.
This is what I have so far which puts the data into a hash.
This will give me a pretty display of all the data.
What I still can't figure out is how to make it only display the note for each one separately (example, Just the "Web Hosting Information" note.
Any help would be appreciated and I hope the above made sense.
Thank you in advance.
What I need is to grab the data for each Note that is after the Body tag. Each file is going to have a different amount of data as well. Oh, and I also need to have the client name within this new data set. Each files notes are also in different orders.
So for example, for all 100+ files, I need to parse out the "Web Hosting Information" and put it into a spreadsheet format.
Here is a partial example of one of the textfiles ( I have stared out sensitive information)
Code:
---
- Name: Client Name
- Contact:
- - Addresses
- - ************
- - Phone_numbers
- - ************
- ************
- - Email_addresses
- - ************
- -
Note 3060148:
- Author: ************
- Written: ************
- About: ************
- Body: |-
<h1>Lead</h1>
************
- Note 2909448:
- Author: ************
- Written: ************
- About: ************
- Body: |-
<h1>Pre-Paid Hours</h1>
N/A
- Note 2909446:
- Author: ************
- Written: ************
- About: ************
- Body: |+
<h1>Domain Names</h1>
************
************
************
************
Admin: ************
Pass: ************
Whois INFO:
Administrative Contact :
************
************
Technical Contact :
************
************
Record expires on ************
- Note 2909443:
- Author: ************
- Written: ************
- About: ************
- Body: |-
<h1>Web Hosting</h1>
************
************
FTP Access
************
************
************
************
************
************
************
************
My end goal is to be able to have ... for example all of the Web Hosting information from each file within one delimited text file.
This is what I have so far which puts the data into a hash.
Code:
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my (%data, $client, $note);
my $datafile = 'filename';
open my $DATAFILE, '<', $datafile or die "can't open '$datafile' $!";
while( my $line = <$DATAFILE>) {
if ( $line =~ /^\s+- Body: (.*\n)/ ) {
$data{$client}{$note}{body} .= $1;
while ( $line = <$DATAFILE> ) {
if ( $line =~ /\s+Note (\d+):/ ) {
$note = $1;
last;
}
$data{$client}{$note}{body} .= $line;
}
next;
}
$client = $1 if $line =~ /^- Name: (.+)/;
$note = $1 if $line =~ /\s+Note (\d+):/;
if ( $note and $line =~ /^\s+- (\w+):\s*(.+)/ ) {
$data{$client}{$note}{$1} = $2;
}
}
print Dumper \%data;
This will give me a pretty display of all the data.
What I still can't figure out is how to make it only display the note for each one separately (example, Just the "Web Hosting Information" note.
Any help would be appreciated and I hope the above made sense.
Thank you in advance.