Satya's blog - 2005/11/
So I had a bunch of shortcuts to images on my Windows box. After scping them to Linux, I had a bunch of lnk files that had nothing to do with the original files. And binary. So I whipped up a short shell command:
for i in *.lnk do echo ln -s `grep -ao [a-zA-Z0-9_]*.jpg $i` $i donepiped the output of that to
edited it in vim to prepend
(if needed; my original images
were in the parent directory) and
remove the trailing .lnk from each line.
Then I ran the shell script and voila, I have symlinks next to windows lnk
(in case I scp them back to a Windows box).
These are archival files so there's no question of frequent updates.
The grep command works with an 'a' for text-mode, 'o' to return just the matched parts (the lnk file contains a full Windows-style path), and the regex matches the filename: any-case letters, number, underline. I know the filenames are limited to that.
A Quote from Terry Pratchett's _Going Postal_
Craftsmen. D'you know what that means? It means men with some pride, who get fed up and leave when they're told to do skimpy work in a rush, no matter what you pay them. So I'm employing people as "craftsmen" now who're barely fit to sweep out a workshop. But you don't care, because if they don't polish a chair with their arse all day you think a man who's done a seven-year apprenticeship is the same as some twerp who can't be trusted to hold a hammer by the right end.-- not said aloud by Mr. Pony, chief engineer for the Grand Trunk clacks company.