shell - Grep/Awk part of directory name to variable iteratively -


i trying part of directory name saved variable can add beginning of file name.

this have far:

var=1 ch=`ls | awk '/[0-9]{2}(?=_.*)/ {if (nr=$var) print $0}'` echo $ch 

a folder name looks 01_startup. echo blank. can't figure out. know if possible shell script? i'm not quite sure order of |'s , how combine commands. thanks.

tree:

benu-master | |--chapter_02_startup |--|--01_source_tree |--|--02_console |--|--03_debug 

and on.

something this?

for c in chapter_*;     v=${c#chapter_}     v=${v%%_*}     echo chapter $c has number $v   # more chapter-processing code here done 

as aside, avoid parsing ls output.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -