#!/bin/perl # A script to extract data from Covid19Clustermap20200331Japan-Detail.txt # (Version 2 on DOI:10.17605/OSF.IO/52NVS 2025-03-15) #Author: TANAKA Sigeto # Graduate School of Arts and Letters, Tohoku University # Kawauti 27-1, Aoba Ku, Sendai, Miyagi, 980-8576 JAPAN # WWW: http://www.sal.tohoku.ac.jp/~tsigeto/ $/ = ""; $\ = "\n" ; $" = $, = "\t" ; %Nmonth = ( Jan => 1, Feb => 2, Mar => 3, Apr => 4, ) ; print qw( id size municipality date0 date1 category direction month day ) ; while(<>){ next unless /^\#\s*data/i ... eof() ; next unless /^ID/ ; my %field; foreach (split /\n/) { s/\s+$//; my($k,$v) = split /:\s*/, $_, 2 ; $field{$k} = $v unless $v eq 'Source'; } my $category = $field{Category}; $category =~ s/\s*\(.*$// ; my $direction = $field{Direction}; $direction =~ s/^(\w+).*$/$1/; my($m, $day) = $field{'Date(5th)'} =~ /^(Jan|Feb|Mar|Apr)\.\s*(\d+)/ ; my $month = $Nmonth{$m} ; print @field{ 'ID', 'Size', 'Municipality', 'Date(occurrence)', 'Date(1st)'}, $category, $direction, $month, $day ; }