From ccfe3181e74227dc8c8ad4b43fa7e4df77bb5b2b Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Wed, 4 Oct 2023 15:42:10 +0100 Subject: Revising dayplan to see days in history - this adds subroute to search in tgz --- calendar/dayplan_revised.pl | 26 ++++++++++++++++++++++++++ unarchive.pl | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100755 unarchive.pl diff --git a/calendar/dayplan_revised.pl b/calendar/dayplan_revised.pl index 53be0b1..36f61da 100755 --- a/calendar/dayplan_revised.pl +++ b/calendar/dayplan_revised.pl @@ -5,6 +5,32 @@ use strict; use warnings; use DateTime; use JSON; +use Archive::Tar; +use IO::Zlib; + +sub search_in_tgz { + my ($archive_file, $search_string) = @_; + my $tar = Archive::Tar->new; + $tar->read($archive_file); + # Iterate through the files in the archive in memory + foreach my $file ($tar->get_files) { + # Check if the file matches your filter (e.g., .txt extension) + if ($file->name =~ /\.md$/) { + # Get the content of the file and process it as needed + my $file_content = $file->get_content; + + # Perform your desired operations on $file_content + # For example, you can print it or manipulate it here + + my @lines = split(/\n/, $file_content); + foreach my $line (@lines) { + if ($line =~ /$search_string/) { + print "File name: " . $file->name . ": " . $line . "\n"; + } + } + } + } +} my $dayplans = '/home/lemon/Documents/Notes/journal/day_plans'; #my $dayplans = "/tmp/dayplans"; diff --git a/unarchive.pl b/unarchive.pl new file mode 100755 index 0000000..810b008 --- /dev/null +++ b/unarchive.pl @@ -0,0 +1,39 @@ +#!/usr/bin/env -S perl + +use strict; +use warnings; +use feature q(say); +use Archive::Tar; + +# This is just a test script to play with the Archive::Tar package + +# Specify the archive file you want to read +my $archive_file = 'journal_archive_aug23.tgz'; + +# Create an Archive::Tar object for reading +my $tar = Archive::Tar->new; + +# Read the archive file +$tar->read($archive_file); + +# Search string +my $search_string = "Joanna"; + +# Iterate through the files in the archive in memory +foreach my $file ($tar->get_files) { + # Check if the file matches your filter (e.g., .txt extension) + if ($file->name =~ /\.md$/) { + # Get the content of the file and process it as needed + my $file_content = $file->get_content; + + # Perform your desired operations on $file_content + # For example, you can print it or manipulate it here + + my @lines = split(/\n/, $file_content); + foreach my $line (@lines) { + if ($line =~ /$search_string/) { + print "File name: " . $file->name . ": " . $line . "\n"; + } + } + } +} -- cgit v1.2.3