Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First, I should say that the easiest way to do this is to use the prename or rename commands.</p> <p>On Ubuntu, OSX (Homebrew package <code>rename</code>, MacPorts package <code>p5-file-rename</code>), or other systems with perl rename (prename):</p> <pre><code>rename s/0000/000/ F0000* </code></pre> <p>or on systems with rename from util-linux-ng, such as RHEL:</p> <pre><code>rename 0000 000 F0000* </code></pre> <p>That's a lot more understandable than the equivalent sed command.</p> <p>But as for understanding the sed command, the sed manpage is helpful. If you run man sed and search for &amp; (using the / command to search), you'll find it's a special character in s/foo/bar/ replacements.</p> <pre><code> s/regexp/replacement/ Attempt to match regexp against the pattern space. If success‐ ful, replace that portion matched with replacement. The replacement may contain the special character &amp; to refer to that portion of the pattern space which matched, and the special escapes \1 through \9 to refer to the corresponding matching sub-expressions in the regexp. </code></pre> <p>Therefore, <code>\(.\)</code> matches the first character, which can be referenced by <code>\1</code>. Then <code>.</code> matches the next character, which is always 0. Then <code>\(.*\)</code> matches the rest of the filename, which can be referenced by <code>\2</code>.</p> <p>The replacement string puts it all together using <code>&amp;</code> (the original filename) and <code>\1\2</code> which is every part of the filename except the 2nd character, which was a 0.</p> <p>This is a pretty cryptic way to do this, IMHO. If for some reason the rename command was not available and you wanted to use sed to do the rename (or perhaps you were doing something too complex for rename?), being more explicit in your regex would make it much more readable. Perhaps something like:</p> <pre><code>ls F00001-0708-*|sed 's/F0000\(.*\)/mv &amp; F000\1/' | sh </code></pre> <p>Being able to see what's actually changing in the s/search/replacement/ makes it much more readable. Also it won't keep sucking characters out of your filename if you accidentally run it twice or something.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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