I would like to write a filepath as a URI in a Unix command-line emulator.
Desired output:
file:///C|/directory/filename.ext
Using sed and pwd I can get close but not quite there because
$ pwd
/c/directory/
…gives me a lower-case drive and no pipe.
Is there a better way?
You can do it with
sed; it has aycommand to do the case-conversion, though it is somewhat convoluted because you would have to go through the hold space as well as the pattern space. It would be easier to use Perl – it probably has one or more modules to do this (such as URI and URI::file), though a simple version could be produced with regular expressions.(Untested code.)