Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The Perl snippet is intriguing, and since Perl is present in most Linux distros, quite useful, but...It doesn't do the job completely. Specifically, there is a problem in translating the URL/URI format from UTF-8 into path Unicode. Let me give an example of the problem. The original URI may be:</p> <pre><code>file:///home/username/Music/Jean-Michel%20Jarre/M%C3%A9tamorphoses/01%20-%20Je%20me%20souviens.mp3 </code></pre> <p>The corresponding path would be:</p> <pre><code>/home/username/Music/Jean-Michel Jarre/Métamorphoses/01 - Je me souviens.mp3 </code></pre> <p><code>%20</code> became space, <code>%C3%A9</code> became 'é'. Is there a Linux command, bash feature, or Perl script that can handle this transformation, or do I have to write a humongous series of sed substring substitutions? What about the reverse transformation, from path to URL/URI?</p> <p>(Follow-up)</p> <p>Looking at <a href="http://search.cpan.org/~gaas/URI-1.54/URI.pm" rel="nofollow noreferrer">http://search.cpan.org/~gaas/URI-1.54/URI.pm</a>, I first saw the as_iri method, but that was apparently missing from my Linux (or is not applicable, somehow). Turns out the solution is to replace the "->path" part with "->file". You can then break that further down using basename and dirname, etc. The solution is thus:</p> <pre><code>path=$( echo "$url" | perl -MURI -le 'chomp($url = &lt;&gt;); print URI-&gt;new($url)-&gt;file' ) </code></pre> <p>Oddly, using "->dir" instead of "->file" does NOT extract the directory part: rather, it formats the URI so it can be used as an argument to mkdir and the like.</p> <p>(Further follow-up)</p> <p>Any reason why the line cannot be shortened to this?</p> <pre><code>path=$( echo "$url" | perl -MURI -le 'print URI-&gt;new(&lt;&gt;)-&gt;file' ) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload