How to parse out specific data in text files and plugs into thespreadsheet

C

cyrusgreats

I need help writing a script in perl that takes text files and parses
out specific data and plugs the data back into the spreadsheet. Can
anyone help me on that..Thanks in advance..
 
J

J. Gleixner

I need help writing a script in perl that takes text files and parses
out specific data and plugs the data back into the spreadsheet. Can
anyone help me on that..Thanks in advance..

The documentation can help, along with thousands of Web sites, and
many, many books.

perldoc perlopentut
perldoc -f split

Books:

http://books.perl.org/
 
C

cyrusgreats

You have left the specifics unspecified...


Errr, what flavor of spreadsheet would that be?

Many of them have there own, uncompatible, data formats.


You're welcome in advance.

Well what meant by specifics, each person in this exmaple have an id
as follows:

Capitan id : 123456
Time arrival : 10:00:56
Time left : 12:11:23

Capitan id : 88456
Time arrival : 1100:56
Time left : 12:17:0

As for spreadsheet, excel file would work!
 
J

J. Gleixner

[...]
Well what meant by specifics, each person in this exmaple have an id
as follows:

Capitan id : 123456
Time arrival : 10:00:56
Time left : 12:11:23

Capitan id : 88456
Time arrival : 1100:56
Time left : 12:17:0

As for spreadsheet, excel file would work!

You will need to put SOME work into this. You'll have to
parse it into the various fields and you could use
Spreadsheet::WriteExcel to create an Excel file.

http://search.cpan.org/~jmcnamara/Spreadsheet-WriteExcel-2.20/lib/Spreadsheet/WriteExcel.pm
 
C

cyrusgreats

I need help writing a script in perl that takes text files and parses
out specific
[...]
Well what meant by specifics, each person in this exmaple have an id
as follows:
Capitan id : 123456
Time arrival : 10:00:56
Time left : 12:11:23
Capitan id : 88456
Time arrival : 1100:56
Time left : 12:17:0
As for spreadsheet, excel file would work!

You will need to put SOME work into this. You'll have to
parse it into the various fields and you could use
Spreadsheet::WriteExcel to create an Excel file.

http://search.cpan.org/~jmcnamara/Spreadsheet-WriteExcel-2.20/lib/Spr...- Hide quoted text -

- Show quoted text

I've already wrote the code for Spreadsheet what is left parsing the
data and put them possibly into the has with their value.
 
J

J. Gleixner

I need help writing a script in perl that takes text files and parses
out specific [...]
Well what meant by specifics, each person in this exmaple have an id
as follows:
Capitan id : 123456
Time arrival : 10:00:56
Time left : 12:11:23
Capitan id : 88456
Time arrival : 1100:56
Time left : 12:17:0
As for spreadsheet, excel file would work!
You will need to put SOME work into this. You'll have to
parse it into the various fields and you could use
Spreadsheet::WriteExcel to create an Excel file.

http://search.cpan.org/~jmcnamara/Spreadsheet-WriteExcel-2.20/lib/Spr...
I've already wrote the code for Spreadsheet what is left parsing the
data and put them possibly into the has with their value.

You could use split or a regular expression.

perldoc -f split
perldoc perlretut

Why not give it a try, post it, and explain what steps are
causing problems. You're not paying us enough to write your
code for you. :)
 
B

Ben Morrow

[please don't quote Google's -hide quoted text- rubbish]

Quoth (e-mail address removed):
I need help writing a script in perl that takes text files and parses
out specific [...]
Well what meant by specifics, each person in this exmaple have an id
as follows:
Capitan id : 123456
Time arrival : 10:00:56
Time left : 12:11:23
Capitan id : 88456
Time arrival : 1100:56
Time left : 12:17:0
As for spreadsheet, excel file would work!

You will need to put SOME work into this. You'll have to
parse it into the various fields and you could use
Spreadsheet::WriteExcel to create an Excel file.
http://search.cpan.org/~jmcnamara/Spreadsheet-WriteExcel-2.20/lib/Spr...-

I've already wrote the code for Spreadsheet what is left parsing the
data and put them possibly into the has with their value.

You mean like

my @records;

{
open my $FILE, '<', 'file.txt'
or die "can't open file.txt: $!";

local $/ = '';

while (my $rec = <$FILE>) {
my @fields = split /\n/, $rec;
my %rec;

for (@fields) {
my ($k, $v) = /([^:]*) \s* : \s* (.*)/x
or die "invalid field: '$_'";
$rec{$k} = $v;
}

push @records, \%rec;
}
}

? Was that really so difficult?

Ben
 
C

cyrusgreats

[please don't quote Google's -hide quoted text- rubbish]

Quoth (e-mail address removed):




(e-mail address removed) wrote:
I need help writing a script in perl that takes text files and parses
out specific
[...]
Well what meant by specifics, each person in this exmaple have an id
as follows:
Capitan id : 123456
Time arrival : 10:00:56
Time left : 12:11:23
Capitan id : 88456
Time arrival : 1100:56
Time left : 12:17:0
As for spreadsheet, excel file would work!
You will need to put SOME work into this. You'll have to
parse it into the various fields and you could use
Spreadsheet::WriteExcel to create an Excel file.

I've already wrote the code for Spreadsheet what is left parsing the
data and put them possibly into the has with their value.

You mean like

my @records;

{
open my $FILE, '<', 'file.txt'
or die "can't open file.txt: $!";

local $/ = '';

while (my $rec = <$FILE>) {
my @fields = split /\n/, $rec;
my %rec;

for (@fields) {
my ($k, $v) = /([^:]*) \s* : \s* (.*)/x
or die "invalid field: '$_'";
$rec{$k} = $v;
}

push @records, \%rec;
}
}

? Was that really so difficult?

Ben- Hide quoted text -

- Show quoted text -

Thanks but I'm getting error: invalid field in this line:
my ($k, $v) = /([^:]*) \s* : \s* (.*)/x
or die "invalid field: '$_'";
 
B

Ben Morrow

Quoth (e-mail address removed):
[please don't quote Google's -hide quoted text- rubbish]
Ben- Hide quoted text -

Which part of the above did you fail to understand?

local $/ = '';

while (my $rec = <$FILE>) {
my @fields = split /\n/, $rec;
my %rec;

for (@fields) {
my ($k, $v) = /([^:]*) \s* : \s* (.*)/x
or die "invalid field: '$_'";
$rec{$k} = $v;
}
Thanks but I'm getting error: invalid field in this line:
my ($k, $v) = /([^:]*) \s* : \s* (.*)/x
or die "invalid field: '$_'";

So... you have a line which doesn't match the pattern. The error message
told you what the line looks like, and which paragraph of the file it was
in. Now change the pattern so it matches what you want it to match.

Ben
 
C

cyrusgreats

Quoth (e-mail address removed):
[please don't quote Google's -hide quoted text- rubbish]
Ben- Hide quoted text -

Which part of the above did you fail to understand?

local $/ = '';
while (my $rec = <$FILE>) {
my @fields = split /\n/, $rec;
my %rec;
for (@fields) {
my ($k, $v) = /([^:]*) \s* : \s* (.*)/x
or die "invalid field: '$_'";
$rec{$k} = $v;
}
Thanks but I'm getting error: invalid field in this line:
my ($k, $v) = /([^:]*) \s* : \s* (.*)/x
or die "invalid field: '$_'";

So... you have a line which doesn't match the pattern. The error message
told you what the line looks like, and which paragraph of the file it was
in. Now change the pattern so it matches what you want it to match.

Ben

thanks I figured that out...
 
C

cyrusgreats

Quoth (e-mail address removed):
[please don't quote Google's -hide quoted text- rubbish]
Ben- Hide quoted text -

Which part of the above did you fail to understand?

local $/ = '';
while (my $rec = <$FILE>) {
my @fields = split /\n/, $rec;
my %rec;
for (@fields) {
my ($k, $v) = /([^:]*) \s* : \s* (.*)/x
or die "invalid field: '$_'";
$rec{$k} = $v;
}
Thanks but I'm getting error: invalid field in this line:
my ($k, $v) = /([^:]*) \s* : \s* (.*)/x
or die "invalid field: '$_'";

So... you have a line which doesn't match the pattern. The error message
told you what the line looks like, and which paragraph of the file it was
in. Now change the pattern so it matches what you want it to match.

Ben

One more thingh before I close my case, what if I want to match the
following:
RDF Throughput R1->R2 (IO/s) : 1609
RDF Throughput R1->R2 (MB/s) : 19.4
I used the this o ne but seems does not work the way I want it:
$match1 =~/RDF Throughput R1->R2 \(MB\/s\)\/;
$match2 =~/RDF Throughput R1->R2 \(IO\/s\)\/;
 
D

Dr.Ruud

(e-mail address removed) schreef:
Ben Morrow:
my ($k, $v) = /([^:]*) \s* : \s* (.*)/x
or die "invalid field: '$_'";

I'm getting error: invalid field in this line:
my ($k, $v) = /([^:]*) \s* : \s* (.*)/x
or die "invalid field: '$_'";

Maybe you understand it better if you change the code line to:

my ($k, $v) = /([^:]*) \s* : \s* (.*)/x
or die "bad data: invalid field '$_' in chunk $.";

?
 
B

Ben Morrow

Quoth "Dr.Ruud said:
(e-mail address removed) schreef:
Ben Morrow:
my ($k, $v) = /([^:]*) \s* : \s* (.*)/x
or die "invalid field: '$_'";

I'm getting error: invalid field in this line:
my ($k, $v) = /([^:]*) \s* : \s* (.*)/x
or die "invalid field: '$_'";

Maybe you understand it better if you change the code line to:

my ($k, $v) = /([^:]*) \s* : \s* (.*)/x
or die "bad data: invalid field '$_' in chunk $.";

die includes $. in the message anyway.

Ben
 
C

cyrusgreats

Quoth "Dr.Ruud said:
(e-mail address removed) schreef:
Ben Morrow:
my ($k, $v) = /([^:]*) \s* : \s* (.*)/x
or die "invalid field: '$_'";
I'm getting error: invalid field in this line:
my ($k, $v) = /([^:]*) \s* : \s* (.*)/x
or die "invalid field: '$_'";
Maybe you understand it better if you change the code line to:
my ($k, $v) = /([^:]*) \s* : \s* (.*)/x
or die "bad data: invalid field '$_' in chunk $.";

die includes $. in the message anyway.

Ben
Any of you guys can help me on the below then I close my case. I want
to match the following but seems does not work the way I want it:


RDF Throughput R1->R2 (IO/s) : 1609
RDF Throughput R1->R2 (MB/s) : 19.4

$match1 =~/RDF Throughput R1->R2 \(MB\/s\)\/;
$match2 =~/RDF Throughput R1->R2 \(IO\/s\)\/;
 
C

cyrusgreats

Quoth "Dr.Ruud" <[email protected]>:
(e-mail address removed) schreef:
Ben Morrow:
my ($k, $v) = /([^:]*) \s* : \s* (.*)/x
or die "invalid field: '$_'";
I'm getting error: invalid field in this line:
my ($k, $v) = /([^:]*) \s* : \s* (.*)/x
or die "invalid field: '$_'";
Maybe you understand it better if you change the code line to:
my ($k, $v) = /([^:]*) \s* : \s* (.*)/x
or die "bad data: invalid field '$_' in chunk $.";
die includes $. in the message anyway.

Any of you guys can help me on the below then I close my case. I want
to match the following but seems does not work the way I want it:

RDF Throughput R1->R2 (IO/s) : 1609
RDF Throughput R1->R2 (MB/s) : 19.4

$match1 =~/RDF Throughput R1->R2 \(MB\/s\)\/;
$match2 =~/RDF Throughput R1->R2 \(IO\/s\)\/;- Hide quoted text -

- Show quoted text -

I figured that out thanks all for your time/help, I used the
following:
\\ (MB\/s\\)
 
J

Josef Moellers

Ben said:
my ($k, $v) = /([^:]*) \s* : \s* (.*)/x

ITYM ([^:]*?)

otherwise the first part would also eat all spaces up to the first
colon, as the re is greedy by default.
 
B

Ben Morrow

Quoth Josef Moellers said:
Ben said:
my ($k, $v) = /([^:]*) \s* : \s* (.*)/x

ITYM ([^:]*?)

otherwise the first part would also eat all spaces up to the first
colon, as the re is greedy by default.

....in which case we might as well have

/(.*?) \s* : .../

as I had in the first place before I changed it :).

Ben
 
H

Henry Law

I need help writing a script in perl that takes text files and parses
out specific data and plugs the data back into the spreadsheet. Can
anyone help me on that..Thanks in advance..

Y'know what, Mr Cyrus the Great? You've just got away with it in this
group. I take my hat off to your astonishing chutzpah. You asked the
most _terrible_ question, wanting highly-paid Perl mavens to do your
work for you ... and eventually someone did. So you carried on asking
dreadful questions, but your charmed life continued and people who have
forgotten more programming than I suspect you'll ever know continued to
give up their time because you couldn't be bothered to put your own in.

I'm amazed. It must be Christmas.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top