Help me batch print text files on the Mac
November 18, 2009 1:19 PM   Subscribe

OS X: I want to batch print all the files in a source-code library. They are actionscript files, which means they are text files that all end in a .as extension. The files are in a complex directory structure (one root folder but files in multiple subfolders), and there are non .as files that I don't want printed. When the files print, I need some kind of separator ( spaces, asterisks, new page...) between each file.

I can't seem to find a FILTERABLE batch printing app for OSX -- one that can print all files (of a certain type or naming scheme) in all folders and subfolders starting at a certain root.

I thought about opening Terminal and doing this:

find . -name "*.as" | xargs cat > outfile.txt

And then printing outfile.txt. That would be perfect except that I won't easily be able to tell where one file begins and another ends. I need

*****************

or some other delimiter between files.

If it matters, this is for OS X Leopard.
posted by grumblebee to Computers & Internet (6 answers total)
 
You're on the right track - try this:
$ for i in `find . -name "*.as"`; do echo ******* >> outfile.txt; echo $i >> outfile.txt; cat $i >> outfile.txt; done
You could also pipe the output of find . -name "*.as" to lpr.
posted by mebibyte at 1:45 PM on November 18, 2009


My quick-and-dirty method would probably be to use the find command you have, but with a "> foo" instead of the pipe, and then use a text editor or sed on foo to replace "^" (beginning-of-line regexp) with "bar\n", where "bar" is a file you've previously filled with "*****************", a new-page character, or whatever you like. That'll give you the names of your .as files interlaced with the name of a file containing the separator text you want, and the proper result when the file foo is piped through xargs, as you have above.
posted by tellumo at 1:45 PM on November 18, 2009


I should tell everyone that I'm a Unix/Linux newbie, though I do understand the basics.

mebibyte, I think that's almost what I want. How do I get newline chars in there so that it's not...

endOfFileOne**********beginningOfFileTwo

What I want is...

endOfFileOne

**********

beginningOfFileTwo

Or will your script do that for me?
posted by grumblebee at 1:59 PM on November 18, 2009


With mebibye's help, I figured it out. Thanks all!

Here's what I'm using.

`find . -name "*.as"`; do echo -e "\n *******\n" >> outfile.txt; cat $i >> outfile.txt; done
posted by grumblebee at 2:10 PM on November 18, 2009


another possibility (although you've already got this worked out, maybe this method will produce a nicer looking output) ---

I just noticed that "enscript" was installed on my mac. I'm pretty sure I didn't install it, so I assume it must be a part of the standard distro. So, perhaps this:

find . -name \*.as | xargs enscript

(untested -- and I believe will try to immediately send the stuff off to the printer, so be careful if you've got 1000 files -- "man enscript" for more options)
posted by lex mercatoria at 3:08 PM on November 18, 2009 [1 favorite]


Enscript is nice. The really old-school way to do this is pr.
posted by hattifattener at 9:26 PM on November 18, 2009


« Older Succumbing to Basecamp, please hope me   |   Help my teenage sister unlock the wonder of... Newer »
This thread is closed to new comments.