[K12OSN] OT -- Not LTSP, but Linux Scripting Question
Kevin Squire
gentgeen at linuxmail.org
Mon Mar 21 19:34:02 UTC 2005
First, I apologize for the OT nature of the post, but I am sure many of
you will know / have done something like this. Also, I really did not
know where else to post the question. If you know somewhere better,
feel free to let me know. :-)
The Asst. Prin. has asked me do something very tedious (I did set myself
up for it, but I could use the "brownie points"), and I need some help
with the script that I am writing to make it less tedious. I have done
a fair bit of scripting, but nothing this advanced, so I need some help.
Some general info: Each teacher right now has a single MS Word document
with every one of his/her students progress reports. (i.e. I have one
file called squire_pr.doc that is 116 pgs for 56 students). The AP
whats them to be a single document (2 or 3 pgs) per student. He does not
care if they stay in .doc format or not, as long as they still look the
same.
So I have taken my squire_pr.doc and printed it to PDF (squire_pr.pdf)
so that I could use a program called pdftk (
http://freshmeat.net/projects/pdftk/ ) and split it up into 116 single
page documents (each one called squire_###.pdf). Then I can use the same
program to join the appropriate pages back together again (so
squire_001.pdf and squire_002.pdf becomes smithJ_04-05_mid.pdf).
I want to put together a script that will automate this stuff (to a
certain point). The teacher sends me two files, the 1 large pdf file
and a text file with student name and the page numbers of the PDF file
that make that student's report. Usually it will be 2 pages, but
sometimes it will be 3 or maybe even 4. The text file would look
something like:
smithJ,001,002
mouseM,003,004
gatesW,005,006,007
I have already done the basics on the script -- setting up variables,
assigning directories, making sure the correct files exist already, etc.
But I don't know how to (1) get the script to read from the text file,
(2) verify that the text file has now spaces and all numbers are in ###
format (3) assign variable to each field in the text file (4) repeat for
every line in the text file.
Some info/example/notes from my script:
=============================================
$inputfile is the 1 big PDF file
$tempdir/$teachername_%03d.pdf part creates a bunch of single PDF's
with the name squire_001.pdf, squire_002.pdf, etc.
$parsefile is the text file with student names, and page numbers
from the PDF that make up there report
==========
pdftk $inputfile burst $tempdir/$teachername_%03d.pdf
# Now the hard part :-)
# Need to read the $parsefile and verify that:
# there are no spaces and that all numbers are in ### format
# if not just give an error of $prasefile has error (adding a line
# number would be nice but not necessary
# and then assign the following:
# $studentname from field 1
# $stupg1 from field 2
# $stupg2 from field 3
# $stupg3 from field 4 for those that have 4 fields
# $stupg4 from field 5 for those that have 5 fields
# then run the command 'pdftk INPUTFILES cat output COMBINEDFILE'
# for every single line in the text file
# where INPUTFILES would be $tempdir/$teachername_$stupgN.pdf where
# N could be 1,2,3 or 4 depending on what was found in text file
NOTE -- sorry this got so long, I hope it all makes sense. And Thank
you in advance for you effort.
--
More information about the K12OSN
mailing list