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

Discussion in 'Perl Misc' started by cyrusgreats@gmail.com, Dec 6, 2007.

  1. Guest

    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..
     
    , Dec 6, 2007
    #1
    1. Advertising

  2. J. Gleixner Guest

    wrote:
    > 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/
     
    J. Gleixner, Dec 6, 2007
    #2
    1. Advertising

  3. Guest

    On Dec 6, 5:38 pm, Tad McClellan <> wrote:
    > <> wrote:
    > > I need help writing a script in perl that takes text files and parses
    > > out specific

    >
    > You have left the specifics unspecified...
    >
    > > data and plugs the data back into the spreadsheet.

    >
    > Errr, what flavor of spreadsheet would that be?
    >
    > Many of them have there own, uncompatible, data formats.
    >
    > > Can
    > > anyone help me on that..

    >
    > Yes.
    >
    > > Thanks in advance..

    >
    > You're welcome in advance.
    >
    > --
    > Tad McClellan
    > email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


    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!
     
    , Dec 7, 2007
    #3
  4. J. Gleixner Guest

    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.

    http://search.cpan.org/~jmcnamara/Spreadsheet-WriteExcel-2.20/lib/Spreadsheet/WriteExcel.pm
     
    J. Gleixner, Dec 7, 2007
    #4
  5. Guest

    On Dec 7, 8:42 am, "J. Gleixner" <>
    wrote:
    > 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.
    >
    > 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.
     
    , Dec 7, 2007
    #5
  6. J. Gleixner Guest

    wrote:
    > On Dec 7, 8:42 am, "J. Gleixner" <>
    > wrote:
    >> 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.
    >>
    >> 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. :)
     
    J. Gleixner, Dec 7, 2007
    #6
  7. Ben Morrow Guest

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

    Quoth :
    > On Dec 7, 8:42 am, "J. Gleixner" <>
    > wrote:
    > > 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.
    > >
    > >

    > 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
     
    Ben Morrow, Dec 7, 2007
    #7
  8. Guest

    On Dec 7, 9:49 am, Ben Morrow <> wrote:
    > [please don't quote Google's -hide quoted text- rubbish]
    >
    > Quoth :
    >
    >
    >
    >
    >
    > > On Dec 7, 8:42 am, "J. Gleixner" <>
    > > wrote:
    > > > 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.

    >
    > >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- 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: '$_'";
     
    , Dec 7, 2007
    #8
  9. Ben Morrow Guest

    Quoth :
    > On Dec 7, 9:49 am, Ben Morrow <> wrote:
    > >
    > > [please don't quote Google's -hide quoted text- rubbish]

    <snip>
    > > Ben- Hide quoted text -


    Which part of the above did you fail to understand?

    <snip>
    > > 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;
    > > }

    <snip>
    > 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
     
    Ben Morrow, Dec 8, 2007
    #9
  10. Guest

    On Dec 7, 4:33 pm, Ben Morrow <> wrote:
    > Quoth :
    >
    > > On Dec 7, 9:49 am, Ben Morrow <> wrote:

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

    > <snip>
    > > > Ben- Hide quoted text -

    >
    > Which part of the above did you fail to understand?
    >
    > <snip>
    >
    > > > 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;
    > > > }

    > <snip>
    > > 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...
     
    , Dec 8, 2007
    #10
  11. Guest

    On Dec 7, 4:33 pm, Ben Morrow <> wrote:
    > Quoth :
    >
    > > On Dec 7, 9:49 am, Ben Morrow <> wrote:

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

    > <snip>
    > > > Ben- Hide quoted text -

    >
    > Which part of the above did you fail to understand?
    >
    > <snip>
    >
    > > > 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;
    > > > }

    > <snip>
    > > 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\)\/;
     
    , Dec 8, 2007
    #11
  12. Dr.Ruud Guest

    Re: How to parse out specific data in text files and plugs into the spreadsheet

    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 $.";

    ?

    --
    Affijn, Ruud

    "Gewoon is een tijger."
     
    Dr.Ruud, Dec 8, 2007
    #12
  13. Ben Morrow Guest

    Re: How to parse out specific data in text files and plugs into the spreadsheet

    Quoth "Dr.Ruud" <>:
    > 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
     
    Ben Morrow, Dec 8, 2007
    #13
  14. Guest

    On Dec 8, 12:21 pm, Ben Morrow <> wrote:
    > Quoth "Dr.Ruud" <>:
    >
    > > 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\)\/;
     
    , Dec 9, 2007
    #14
  15. Guest

    On Dec 8, 8:02 pm, wrote:
    > On Dec 8, 12:21 pm, Ben Morrow <> wrote:
    >
    >
    >
    > > Quoth "Dr.Ruud" <>:

    >
    > > > 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\)\/;- Hide quoted text -
    >
    > - Show quoted text -


    I figured that out thanks all for your time/help, I used the
    following:
    \\ (MB\/s\\)
     
    , Dec 9, 2007
    #15
  16. Ben Morrow wrote:

    > 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.

    --
    These are my personal views and not those of Fujitsu Siemens Computers!
    Josef Möllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize (T. Pratchett)
    Company Details: http://www.fujitsu-siemens.com/imprint.html
     
    Josef Moellers, Dec 10, 2007
    #16
  17. Ben Morrow Guest

    Quoth Josef Moellers <>:
    > Ben Morrow wrote:
    >
    > > 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
     
    Ben Morrow, Dec 10, 2007
    #17
  18. Henry Law Guest

    wrote:
    > 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.

    --

    Henry Law Manchester, England
     
    Henry Law, Dec 15, 2007
    #18
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. precious
    Replies:
    0
    Views:
    947
    precious
    May 22, 2004
  2. Harry Zoroc
    Replies:
    1
    Views:
    948
    Gregory Vaughan
    Jul 12, 2004
  3. Replies:
    4
    Views:
    959
    M.E.Farmer
    Feb 13, 2005
  4. Replies:
    2
    Views:
    870
Loading...

Share This Page