I have a folder tree of month names using the first 3 three letters (Jan, Feb, Mar). Inside each folder are text files, 1 for each day of the month. Titled 1.txt, 2.txt, 3.txt and so on and so on.
In my text file, I have the Month, Day, Year and Text. I want to automatically make a script go through my folder tree and input text where it should go (at the bottom of the correct Month/day file). A sample of the INPUT file is
A sample of the file I am OUTPUTTING TOJan 1, 1915 (Birthday) Franck Pourcel - singer Jan 3, 1926 (Birthday) George Martin - singer Jan 3, 1945 (Birthday) Stephen Stills - singer Jan 3, 1946 (Birthday) John Paul Jones - singer
The output file only has the year, a space, and the TEXT. The other data from the INPUT file is used to locate the correct file.1963 G Woods succeeds Eugene Black as president of the World Bank 1964 Federation of Rhodesia & Nyasaland dissolved 1965 International Cooperation Year begins
This is what I have so far. I think it would work if the regex was matching, but it's not. Can anyone help me with this? I did the best I could.
#!/usr/bin/perl use warnings; use strict; open(LOG, "source.txt") or die "Error: $!"; my @lines = <LOG>; close(LOG); foreach my $line (@lines) { $line =~ m/(\w)\s+(\d+),\s+(\d+)\s+(\(Birthday\)\s.+)/i; # 1 is m +onth, 2 is day of month, 3 is year, 4 is the text print "$1 $2 $3 $4\n"; open(OUT, ">> $1/$2.txt") or die "Error"; # write our line appendi +ng to the bottom of the file print OUT "$3, $4\n"; } print "Done";
In reply to Simple line regex again by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |