#!/usr/bin/perl # ########################################################################## # # This is PERL program "onefileperline.pl" # Feb 7th, 1998 # Eric Larson, using some code from John laPlante # Feb 8, 1998 # Bryan Heidorn, Changed sort to sort by word then line number. #Feb 15, 2005 # Bryan Heidorn, Crippled the program so it will not do the whole exercise for them # Made change from being one one per line to one line per file. # Nov 4, 2005 # Bryan Heidorn, changed to convert the tags as they are written to the output # If there are multiple tags (and clauses) in the same line they are written as two different lines # # Program purpose # This program accepts a file name and produces a flock of files, one for each line in the original file.# # Command Line Syntax # onefileperline.pl "Input Filename" # # File opening and creation behavior # The input file must exist. # file names is still a problem. # # Input file must have the biogeomancer locality type tages e.g. # # Properties of output file # -- The words are devoid of punctuation and have been converted to lowercase. # -- The - symbol has been converted to a space before processing. # -- Each word is followed by a TAB character. # -- The line ends with a newline character. # ########################################################################### # Test for proper command line, exit if not $numargs = @ARGV ; if ($numargs < 2 ) { print "Usage: ", $0, " \"Input_Text_File Output_Directory\n" ; die ; } # Create variables to hold filenames parsed from the command line $infile = $ARGV[0] ; $outputDir = $ARGV[1]; # Open the Input File unless (open(INFILE, "$infile")) { if (!(-e "$infile")) { die ("$0 Died -- Input file $infile does not exist \n") ; } elsif (!(-r "$infile")) { die ("$0 Died -- No read permission for $infile \n") ; } elsif (-z "$infile") { die ("$0 Died -- Input file $infile is empty \n") ; } else { die ("$0 Died -- Input file $infile cannot be opened \n") ; } } #$line = ; # Seed the while loop with the first line of text $linenumber= 1 ; # Counter to track the line number in the file #i Use this line number as a file name. while ($line = ) { # Read a line of text chop($line); # Remove the ending newline # loop until there are no more tags unless (open (OUTFILE, ">>./$outputDir/$linenumber.txt")) { if (!(-w "./$outputDir/$linenumber.txt")) { die ("$0 Died -- No write permissions to $outputDir. The directory must exist.\n") ; } else { die ("$0 Died -- Outfile $outputDir cannot be opened \n") ; } } print OUTFILE $line; close (OUTFILE); $linenumber++ ; # Iterate the line counter } close (INFILE) ; # Close the two files