Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: translate all sequences of whitespace/underscores to single dashes



On Sun, Aug 16, 2015 at 5:20 PM, Emanuel Berg <embe8573@xxxxxxxxxxxxx>
wrote:

> How can I do this directly and only in zsh, i.e.
> not using tr (translate characters)?
>
>     # whitespace(s) and underscore(s) -> (a single) dash
>     new_name=${new_name//[_ ]/-}
>     new_name=`echo $new_name | tr -s "-"`
>

The patterns are the same as those for filename generation (so see that
section of "man zshexpn"). The solution is to enable extended_glob support.

# setopt extendedglob
# x='a b_c_  d'
# print ${x//[_ ]##/-}
a-b-c-d


-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank


Messages sorted by: Reverse Date, Date, Thread, Author