Dave been asked to upgrade some legacy software to the new vendor supported version. As far as Dave can tell thus far, the software is for the most part the same, however the scribbled notes left by the old sysadmin tell him that there's a lot of custom scripts dumped in with the application itself. In order to save time, Dave has been instructed to merge the two directories to keep changes to the scripts to a minimum....
Firstly, Dave moved the old application to /usr/local/foo-old and installed the new version in /usr/local/foo/. He now wishes to merge the two directories as follows:
if a file is in /usr/local/foo-old/ but not in /usr/local/foo/ it should be copied to to /usr/local/foo/ and a log file should be kept to notify changes.
the permissions on every file in /usr/local/foo-old/ should be the same as /usr/local/foo/
He's a bit baffled as how to do this automatically though. Can you help him?
Bob has been doing a lot of writing recently (plain text files that he stores in ~/doc) and he's simply curious about how many words per line he writes on average. He's stumped how to work this out using only the standard UNIX tools though...
Well tuomov correctly identified Problem 2 as the famous Bin Packing problem and although it can be solved to a certain degree mdlbear was correct to point out that my wording was flawed in the use of optimal. Apologies. Nobody stepped up to write a solution in sh but pauldoo did provide a solution written in Ruby.
Anyway back to our scheduled programme..
With 'HTML 4.0 for Dummies' at his side Bob spent his weeekend writing up a simple series of webpages to display his best photographs online. Each page simply linked each image below each other like so:
It wasn't the nicest looking page in the world but Bob was happy with what he'd achieved. It wasn't until he was skimming the 'top tips' section at the back of the book Bob discovered that he'd missed width and height attributes of the img tags however. Although the images would still display the page wouldn't render as nicely as the different photos took different times to load making the 'page jump' and after reading that tip Bob kept noticing! Bob was annoyed but he didn't have time to open up each photograph in the Gimp and get its corresponding height and width to fill out the img tags manually. Annoyed Bob threw his keyboard at his monitor and stumbled off to bed.
Well done to everybody that had a go at the first problem. skx provided a neat and tidy script, tuomov showed that he's apparently comfortable with pipelining and tjernobyl came up with a solution with a bit of help from everyone's best friend/enemy Perl.
Anyway, second problem again a day late!
Alice was feeling tired and a bit fed up after a long and laborious week of work. So she settled down and decided she'd watch her favourite DVD to cheer her up. Unfortunately though, she found that due to deep scratches in the DVD it wouldn't play. Frustrated and angry at the situation she'd got herself into she promised to herself she'd never let it happen again. So that night, one by one, she backed up and compressed all of her legally purchased DVDs on to a directory on her PC.
Over the next few days she's decided she'd like to copy a subset of files to DVD. The problem she has however is that not all the files will fit on a single DVD and at the same time she'd like to make the most of the space on each DVD as much as possible. So what she really needs help doing is determining the optimal subset of files (which range from 500MB to 1GB each) to burn to DVD1 (wasting the least amount of space). Oh and ideally she'd like to keep things from the same series together and organised. Can you help you Alice out?
Okay finally first problem a date later that originally announced.
Bob finally gave in and went digital a few years ago and since then he's accumulated a vast number of photographs. Sadly each week as he's taken more and more photos and his memory card has filled he's uploaded them to his PC without much thought. As a result Bob finds that his photos directory (~/photos) is now getting out of hand - one thousand files with randomally assigned names. Bob figures that at least having some sort of hierarchy so that the photos were in sub-directories by modified date would be a start.
Can you help Bob out?
Solutions in comments please. Please make sure you put your solution within a <code> or <pre>. Oh yeah and I'm not sure if I should screen the comments at first so other people have a chance to answer? What do people think? I'd like to hear general feedback too!