work on ods spreadsheet with perl in ubuntu

The included file lists burial information for a nearby cemetery where my sister is the secretary.  fyi: interment means burial.  She has interment  books that are old.  I am trying to put the information in electronic form because the books are wearing out and the information should  not be lost.

I would like to run a program (in perl I suppose -- linux for sure), that divides the included file into seperate files for each year of interment.  The earliest file, "1939 new alexandria cemetery.ods", would look like:
22      662      1939-12-20      Mary Elizabeth Burge      natural cause      Brilliant      J. A. Rigley      Smithfield
28      8280      1939-12-30      Milton Eugene Reddine      cerebral hemmorage      Mingo Junction      A. G. Murphy      Mingo Junction
23      662      1939-12-30      Margaret Jane Davis      advanced age      Brilliant      J. C. McClave      Steubenville, OH
617      654      1939-12-30      Daniel Mathues      cancer      Steubenville, OH      J. C. McClave      Steubenville, OH
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nociSoftware EngineerCommented:
The easiest would be to save it as CSV file and then grep over it with:
in principal...,

head -n 1 new-alexandria-cemetary.csv >new-alexandria-cemetary.head
for year in $( seq 1939 2015)
   cat new-alexandria-cemetary.head > new-alexandria-cemetary-$year.csv
   grep ",${year}-" new-alexandria-cemetary.csv >>new-alexandria-cemetary-$year.csv

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dwcroninAuthor Commented:
I have trouble running your code.  Here is the csv file I'm tryin to  work on:
nociSoftware EngineerCommented:
The code is bash shell code.
Not perl.  i was in a hurry this morning...

Your csv (saved .ods as .CSV, with , as separator, & " as string delimiter.)  is now attached.
I slightly modified the script to end with the current year (starting from 1939 still)
(attached )
Here's a perl script with error handling (which could be increased or left out if you choose).


use warnings;
use strict;

my $csv_file = 'new-alexandria-cemetery.csv';
open my $fh, '<', $csv_file or die "failed to open '$csv_file' <$!>";

my %interment;
my $header = <$fh>;
while (<$fh>) {
    my ($year) = (split /,/)[2] =~ /^(\d+)/;
    push @{ $interment{$year} }, $_;
close $fh;

foreach my $year (sort keys %interment) {
    my $file = "${year}_intement.csv";
    open my $fh, '>', $file or die "failed to open '$file' <$!>";
    print $fh $header, @{ $interment{$year} };
    close $fh;

Open in new window

I should mention that there are perl modules available to both read and write speadsheet files which allows you to bypass the export/import of csv files.  The modules also have the advantage of being able to format the cells as well as applying other normal spreadsheet features, which can't be done via a csv file.  The drawback is that the syntax is a lot more involved than dealing with csv files.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.