Skip to main content
added 8 characters in body
Source Link
Stéphane Chazelas
  • 553.6k
  • 92
  • 1.1k
  • 1.6k
  • `...` is a deprecated form of command substitution from sh/csh, and like the modern $(...) form (from ksh), also needs to be quoted. But it shouldn't be used as it comes with many problems of its own. In any case, it's not used to quote text, only to expand to the output of some commentcommand. The best kind of quotes for sed code which tends to contain characters such as \ or $ are single quotes ('...') inside which in Bourne-like shells including zsh, notno character is treated specially by the shell.
  • to print some text verbatim, use print -r - $f (ksh-style, though you'd need quotes in ksh) or printf '%s\n' $f (POSIX-style, would also need quotes in sh), or echo -E - $f (zsh-specific) not echo $f which breaks on values of $f starting with - or containing backslash. See also the <<< $f here-string syntax.
  • +, {4} and (...) are extended (or perl) regexp operator, so you'd need -E or -P options for sed, where supported. The basic regexp equivalents are \{1,\}, \{4\} and \(...\) (which explains why your \2 is not matched). Some sed implementations also support \+.
  • [A-Za-z] matches characters that sort between A and Z and a and z depending on the sed implementation it may or may not match on ç or œ, it doesn't with zsh's own globs. ź would likely sort after z so be excluded. Same for letters in other scripts. Use [[:alpha:]] to match on letters (or more generally character used in human language words). Many Albums would likely have space or numbers or ., '... Using [^-] for any character other than - may be a better approach. Or like in zmv above, rely on the fact that the preceding * will be greedy.
  • remember that sed is line-based and text-based, so doesn't process the file name as a whole but each line of the file name individually (would only be a problem for file names containing newlines or non-characters such as characters encoded in a charset other than that of the locale).
  • When using variable data in arguments to commands, you need -- to mark the end of options. mv $f ... would treat $f as an option if it started with -.
  • `...` is a deprecated form of command substitution from sh/csh, and like the modern $(...) form (from ksh), also needs to be quoted. But it shouldn't be used as it comes with many problems of its own. In any case, it's not used to quote text, only to expand to the output of some comment. The best kind of quotes for sed code which tends to contain characters such as \ or $ are single quotes ('...') inside which in Bourne-like shells, not character is treated specially by the shell.
  • to print some text verbatim, use print -r - $f (ksh-style, though you'd need quotes in ksh) or printf '%s\n' $f (POSIX-style, would also need quotes), or echo -E - $f (zsh-specific) not echo $f which breaks on values of $f starting with - or containing backslash. See also the <<< $f here-string syntax.
  • +, {4} and (...) are extended (or perl) regexp operator, so you'd need -E or -P options for sed, where supported. The basic regexp equivalents are \{1,\}, \{4\} and \(...\) (which explains why your \2 is not matched). Some sed implementations also support \+.
  • [A-Za-z] matches characters that sort between A and Z and a and z depending on the sed implementation it may or may not match on ç or œ, it doesn't with zsh's own globs. ź would likely sort after z so be excluded. Same for letters in other scripts. Use [[:alpha:]] to match on letters (or more generally character used in human language words). Many Albums would likely have space or numbers or ., '... Using [^-] for any character other than - may be a better approach. Or like in zmv above, rely on the fact that the preceding * will be greedy.
  • remember that sed is line-based and text-based, so doesn't process the file name as a whole but each line of the file name individually (would only be a problem for file names containing newlines or non-characters such as characters encoded in a charset other than that of the locale).
  • When using variable data in arguments to commands, you need -- to mark the end of options. mv $f ... would treat $f as an option if it started with -.
  • `...` is a deprecated form of command substitution from sh/csh, and like the modern $(...) form (from ksh), also needs to be quoted. But it shouldn't be used as it comes with many problems of its own. In any case, it's not used to quote text, only to expand to the output of some command. The best kind of quotes for sed code which tends to contain characters such as \ or $ are single quotes ('...') inside which in Bourne-like shells including zsh, no character is treated specially by the shell.
  • to print some text verbatim, use print -r - $f (ksh-style, though you'd need quotes in ksh) or printf '%s\n' $f (POSIX-style, would also need quotes in sh), or echo -E - $f (zsh-specific) not echo $f which breaks on values of $f starting with - or containing backslash. See also the <<< $f here-string syntax.
  • +, {4} and (...) are extended (or perl) regexp operator, so you'd need -E or -P options for sed, where supported. The basic regexp equivalents are \{1,\}, \{4\} and \(...\) (which explains why your \2 is not matched). Some sed implementations also support \+.
  • [A-Za-z] matches characters that sort between A and Z and a and z depending on the sed implementation it may or may not match on ç or œ, it doesn't with zsh's own globs. ź would likely sort after z so be excluded. Same for letters in other scripts. Use [[:alpha:]] to match on letters (or more generally character used in human language words). Many Albums would likely have space or numbers or ., '... Using [^-] for any character other than - may be a better approach. Or like in zmv above, rely on the fact that the preceding * will be greedy.
  • remember that sed is line-based and text-based, so doesn't process the file name as a whole but each line of the file name individually (would only be a problem for file names containing newlines or non-characters such as characters encoded in a charset other than that of the locale).
  • When using variable data in arguments to commands, you need -- to mark the end of options. mv $f ... would treat $f as an option if it started with -.
added 8 characters in body
Source Link
Stéphane Chazelas
  • 553.6k
  • 92
  • 1.1k
  • 1.6k
for old in *'PESTE NOIRE'*; do
  new=$(print -r - $f | sed  '
    :1
    $!{
      N;b1
    }
    s/\(.*-\)\(.*\) ([[:digit:]]\{4\})$/\1 \3\2/'
  ) && [[ $old != $new ]] &&
    mv -i -- $old $new
done
for old in *'PESTE NOIRE'*; do
  new=$(print -r - $f | sed  '
    $!{
      N;b1
    }
    s/\(.*-\)\(.*\) ([[:digit:]]\{4\})$/\1 \3\2/'
  ) && [[ $old != $new ]] &&
    mv -i -- $old $new
done
for old in *'PESTE NOIRE'*; do
  new=$(print -r - $f | sed  '
    :1
    $!{
      N;b1
    }
    s/\(.*-\)\(.*\) ([[:digit:]]\{4\})$/\1 \3\2/'
  ) && [[ $old != $new ]] &&
    mv -i -- $old $new
done
added 293 characters in body
Source Link
Stéphane Chazelas
  • 553.6k
  • 92
  • 1.1k
  • 1.6k
  • `...` is a deprecated form of command substitution from sh/csh, and like the modern $(...) form (from ksh), also needs to be quoted. But it shouldn't be used as it comes with many problems of its own. In any case, it's not used to quote text, only to expand to the output of some comment. The best kind of quotes for sed code which tends to contain characters such as \ or $ are single quotes ('...') inside which in Bourne-like shells, not character is treated specially by the shell.
  • to print some text verbatim, use print -r - $f (ksh-style, though you'd need quotes in ksh) or printf '%s\n' $f (POSIX-style, would also need quotes), or echo -E - $f (zsh-specific) not echo $f which breaks on values of $f starting with - or containing backslash. See also the <<< $f here-string syntax.
  • +, {4} and (...) are extended (or perl) regexp operator, so you'd need -E or -P options for sed, where supported. The basic regexp equivalents are \{1,\}, \{4\} and \(...\) (which explains why your \2 is not matched). Some sed implementations also support \+.
  • [A-Za-z] matches characters that sort between A and Z and a and z depending on the sed implementation it may or may not match on ç or œ, it doesn't with zsh's own globs. ź would likely sort after z so be excluded. Same for letters in other scripts. Use [[:alpha:]] to match on letters (or more generally character used in human language words). Many Albums would likely have space or numbers or ., '... Using [^-] for any character other than - may be a better approach. Or like in zmv above, rely on the fact that the preceding * will be greedy.
  • remember that sed is line-based and text-based, so doesn't process the file name as a whole but each line of the file name individually (would only be a problem for file names containing newlines or non-characters such as characters encoded in a charset other than that of the locale).
  • When using variable data in arguments to commands, you need -- to mark the end of options. mv $f ... would treat $f as an option if it started with -.
  • `...` is a deprecated form of command substitution from sh/csh, and like the modern $(...) form (from ksh), also needs to be quoted. But it shouldn't be used as it comes with many problems of its own.
  • to print some text verbatim, use print -r - $f (ksh-style, though you'd need quotes in ksh) or printf '%s\n' $f (POSIX-style, would also need quotes), or echo -E - $f (zsh-specific) not echo $f which breaks on values of $f starting with - or containing backslash. See also the <<< $f here-string syntax.
  • +, {4} and (...) are extended (or perl) regexp operator, so you'd need -E or -P options for sed, where supported. The basic regexp equivalents are \{1,\}, \{4\} and \(...\) (which explains why your \2 is not matched). Some sed implementations also support \+.
  • [A-Za-z] matches characters that sort between A and Z and a and z depending on the sed implementation it may or may not match on ç or œ, it doesn't with zsh's own globs. ź would likely sort after z so be excluded. Same for letters in other scripts. Use [[:alpha:]] to match on letters (or more generally character used in human language words). Many Albums would likely have space or numbers or ., '... Using [^-] for any character other than - may be a better approach. Or like in zmv above, rely on the fact that the preceding * will be greedy.
  • remember that sed is line-based and text-based, so doesn't process the file name as a whole but each line of the file name individually (would only be a problem for file names containing newlines or non-characters such as characters encoded in a charset other than that of the locale).
  • When using variable data in arguments to commands, you need -- to mark the end of options. mv $f ... would treat $f as an option if it started with -.
  • `...` is a deprecated form of command substitution from sh/csh, and like the modern $(...) form (from ksh), also needs to be quoted. But it shouldn't be used as it comes with many problems of its own. In any case, it's not used to quote text, only to expand to the output of some comment. The best kind of quotes for sed code which tends to contain characters such as \ or $ are single quotes ('...') inside which in Bourne-like shells, not character is treated specially by the shell.
  • to print some text verbatim, use print -r - $f (ksh-style, though you'd need quotes in ksh) or printf '%s\n' $f (POSIX-style, would also need quotes), or echo -E - $f (zsh-specific) not echo $f which breaks on values of $f starting with - or containing backslash. See also the <<< $f here-string syntax.
  • +, {4} and (...) are extended (or perl) regexp operator, so you'd need -E or -P options for sed, where supported. The basic regexp equivalents are \{1,\}, \{4\} and \(...\) (which explains why your \2 is not matched). Some sed implementations also support \+.
  • [A-Za-z] matches characters that sort between A and Z and a and z depending on the sed implementation it may or may not match on ç or œ, it doesn't with zsh's own globs. ź would likely sort after z so be excluded. Same for letters in other scripts. Use [[:alpha:]] to match on letters (or more generally character used in human language words). Many Albums would likely have space or numbers or ., '... Using [^-] for any character other than - may be a better approach. Or like in zmv above, rely on the fact that the preceding * will be greedy.
  • remember that sed is line-based and text-based, so doesn't process the file name as a whole but each line of the file name individually (would only be a problem for file names containing newlines or non-characters such as characters encoded in a charset other than that of the locale).
  • When using variable data in arguments to commands, you need -- to mark the end of options. mv $f ... would treat $f as an option if it started with -.
added 1425 characters in body
Source Link
Stéphane Chazelas
  • 553.6k
  • 92
  • 1.1k
  • 1.6k
Loading
added 1425 characters in body
Source Link
Stéphane Chazelas
  • 553.6k
  • 92
  • 1.1k
  • 1.6k
Loading
Source Link
Stéphane Chazelas
  • 553.6k
  • 92
  • 1.1k
  • 1.6k
Loading