Setting path names

I am in a directory called

/abstracts

Doing

tree -d 

gives

.
 geo1936
    geo01n01
    geo01n02
    geo01n03
 geo1937
    geo02n01
    geo02n02
    geo02n03
    geo02n04
 geo1938
    geo03n01
    geo03n02
    geo03n03
    geo03n04

I want to create pathnames to be

geo1936/geo01n01
geo1936/geo01n02
geo1936/geo01n03

geo1937/geo02n01

geo1937/geo02n02
geo1937/geo02n03
geo1937/geo02n04

etc

so that I can loop through them

???

find . -type d
1 Like

Ok. So now this is my actual command

find -type d -exec ls -d1 {} \; | cut -c 3- | grep "/" | awk -v year= '{print "cd "$1"; /home/chrisd/srv/sunny/hstmy/bin/tcsh/georom_replaceText.tcsh --year= *.html; cd ../.." }'

which returns

cd tle2007/tle26n02; /home/chrisd/srv/sunny/hstmy/bin/tcsh/georom_replaceText.tcsh --year= *.html; cd ../..
cd tle2007/tle26n09; /home/chrisd/srv/sunny/hstmy/bin/tcsh/georom_replaceText.tcsh --year= *.html; cd ../..
cd tle2007/tle26n10; /home/chrisd/srv/sunny/hstmy/bin/tcsh/georom_replaceText.tcsh --year= *.html; cd ../..
cd tle2007/tle26n11; /home/chrisd/srv/sunny/hstmy/bin/tcsh/georom_replaceText.tcsh --year= *.html; cd ../..
cd tle2007/tle26n12; /home/chrisd/srv/sunny/hstmy/bin/tcsh/georom_replaceText.tcsh --year= *.html; cd ../..
cd tle2008/tle27n01; /home/chrisd/srv/sunny/hstmy/bin/tcsh/georom_replaceText.tcsh --year= *.html; cd ../..
cd tle2008/tle27n02; /home/chrisd/srv/sunny/hstmy/bin/tcsh/georom_replaceText.tcsh --year= *.html; cd ../..
cd tle2008/tle27n03; /home/chrisd/srv/sunny/hstmy/bin/tcsh/georom_replaceText.tcsh --year= *.html; cd ../..

Finally I want to put the year in the option

--year=

such that the command returns

cd tle2007/tle26n09; /home/chrisd/srv/sunny/hstmy/bin/tcsh/georom_replaceText.tcsh --year=2007 *.html; cd ../..
cd tle2007/tle26n10; /home/chrisd/srv/sunny/hstmy/bin/tcsh/georom_replaceText.tcsh --year=2007 *.html; cd ../..
cd tle2007/tle26n11; /home/chrisd/srv/sunny/hstmy/bin/tcsh/georom_replaceText.tcsh --year=2007 *.html; cd ../..
cd tle2007/tle26n12; /home/chrisd/srv/sunny/hstmy/bin/tcsh/georom_replaceText.tcsh --year=2007 *.html; cd ../..
cd tle2008/tle27n01; /home/chrisd/srv/sunny/hstmy/bin/tcsh/georom_replaceText.tcsh --year=2008 *.html; cd ../..
cd tle2008/tle27n02; /home/chrisd/srv/sunny/hstmy/bin/tcsh/georom_replaceText.tcsh --year=2008 *.html; cd ../..
cd tle2008/tle27n03; /home/chrisd/srv/sunny/hstmy/bin/tcsh/georom_replaceText.tcsh --year=2008 *.html; cd ../..

You can use the following minor modification in your command :

Instead of

$$ tree -d

Use

$$ tree -fi

But this will also displays the directory names in the listing.so to avoid them,use the following:

$$ tree -fi|egrep "^\.\/.+\/.+"|cut -c 3-

This will output only files recursively with their relative pathnames( ie, pathnames relative to their current directory) and donot displays directory names;

You will get your output.

In order to traverse through the list, use following:

$$ set `tree -fi|egrep "^\.\/.+\/.+"|cut -c 3-`
$$ while [ $1 != "" ]
>do
>echo $1
>shift
>done
.....output displaying files

This is the updated code

tree -fid | awk 'BEGIN{FS="/"; OFS="/"}; NF == 3 {print "cd "$0"; /home/chrisd/srv/sunny/hstmy/bin/tcsh/georom_replaceText.tcsh --year= *.html; cd ../.." }'

This gives

cd ./tle2007/tle26n09; /home/chrisd/srv/sunny/hstmy/bin/tcsh/georom_replaceText.tcsh --year= *.html; cd ../..
cd ./tle2007/tle26n10; /home/chrisd/srv/sunny/hstmy/bin/tcsh/georom_replaceText.tcsh --year= *.html; cd ../.. 
cd ./tle2007/tle26n11; /home/chrisd/srv/sunny/hstmy/bin/tcsh/georom_replaceText.tcsh --year= *.html; cd ../..
cd ./tle2007/tle26n12; /home/chrisd/srv/sunny/hstmy/bin/tcsh/georom_replaceText.tcsh --year= *.html; cd ../.. 
cd ./tle2008/tle27n01; /home/chrisd/srv/sunny/hstmy/bin/tcsh/georom_replaceText.tcsh --year= *.html; cd ../..
cd ./tle2008/tle27n02; /home/chrisd/srv/sunny/hstmy/bin/tcsh/georom_replaceText.tcsh --year= *.html; cd ../..
cd ./tle2008/tle27n03; /home/chrisd/srv/sunny/hstmy/bin/tcsh/georom_replaceText.tcsh --year= *.html; cd ../..

---------- Post updated at 12:20 PM ---------- Previous update was at 11:34 AM ----------

Done it

tree -fid | awk 'BEGIN{FS="/"; OFS="/"}; NF == 3 {print "cd "$0"; /home/chrisd/srv/sunny/hstmy/bin/tcsh/georom_replaceText.tcsh --year="$2" *.html; cd ../.." }' | awk '{gsub(/"--year=geo"|"--year=tle"/,"--year="); print}'

which produces the correct output