Zsh substitution, can’t do regex with repetition

regexshellzsh

I'm trying to perform ZSH variable substitution, but I'm having to do it the lame way, by piping through cut. Is it possible to perform this operation entirely within ZSH?


i=./riak.logs.cloudstoragea08/2014-08-07T15:47:49.540310/console.log.2014-07-31-05
echo ${${i/\.\//}:s/\/*//}
riak.logs.cloudstoragea08/2014-08-07T15:47:49.540310/console.log.2014-07-31-05
echo ${${i/\.\//}}
riak.logs.cloudstoragea08/2014-08-07T15:47:49.540310/console.log.2014-07-31-05
echo ${echo ${i/\.\//} | cut -d/ -f 1}
zsh: bad substitution:
echo $(echo ${i/\.\//} | cut -d/ -f 1)
riak.logs.cloudstoragea08

Best Answer

i=./riak.logs.cloudstoragea08/2014-08-07T15:47:49.540310/console.log.2014-07-31-05
j=${i:2}
echo ${j%%/*}

Alternatively:

expr $i : '\.\/\([^/]*\)/'