Setting path names


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Setting path names
# 1  
Old 04-09-2012
Setting path names

I am in a directory called

Code:
/abstracts

Doing

Code:
tree -d

gives

Code:
.
├── geo1936
│   ├── geo01n01
│   ├── geo01n02
│   └── geo01n03
├── geo1937
│   ├── geo02n01
│   ├── geo02n02
│   ├── geo02n03
│   └── geo02n04
├── geo1938
│   ├── geo03n01
│   ├── geo03n02
│   ├── geo03n03
│   └── geo03n04

I want to create pathnames to be

Code:
geo1936/geo01n01
geo1936/geo01n02
geo1936/geo01n03

geo1937/geo02n01

geo1937/geo02n02
geo1937/geo02n03
geo1937/geo02n04

etc

so that I can loop through them
# 2  
Old 04-09-2012
???
Code:
find . -type d

This User Gave Thanks to yazu For This Post:
# 3  
Old 04-09-2012
Ok. So now this is my actual command

Code:
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

Code:
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

Code:
--year=

such that the command returns

Code:
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 ../..

# 4  
Old 04-09-2012

You can use the following minor modification in your command :

Instead of

Code:
$$ tree -d

Use

Code:
$$ tree -fi

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

Code:
$$ 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:

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


Last edited by Epsilon; 04-09-2012 at 01:38 PM..
# 5  
Old 04-09-2012
This is the updated code

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

Code:
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

Code:
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
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Setting up a private path

Hi all, This is probably a very simple question but I couldn't even think of how to phrase it intelligently so google could tell me the answer. Basically I am a user on a server, I am not the admin and do not have root privileges. I have downloaded a bunch of programs that I need to use and... (2 Replies)
Discussion started by: DavyK1984
2 Replies

2. UNIX for Dummies Questions & Answers

Removing path name from list of file names

I have this piece of code printf '%s\n' $pth*.msf | tr ' ' '\n' | sort -t '-' -k7 -k6r \ | awk -F- '{c=($6$7!=p&&FNR!=1)?ORS:"";p=$6$7}{printf("%c%s\n",c,$0)}' When I run it I get /home/chrisd/tatsh/branches/terr0.50/darwin/n02-z30-dsr65-terr0.50-dc0.002-8x6drw-csq.msf... (8 Replies)
Discussion started by: kristinu
8 Replies

3. Shell Programming and Scripting

Setting up a path in UNIX

I have the following script "test". When i tried to execute it, I am not able to run it. I dunno why ? Then i tried getting the first few lines of the script which is displayed below: $head -10 test #!/bin/ksh PROG=$0;export PROG ORAUSER=`get_inf_env INFORM_DB_ACCOUNT`;export ORAUSER... (13 Replies)
Discussion started by: bobby1015
13 Replies

4. Shell Programming and Scripting

want only file names (not whole path) in shell script

hi i wrote following script, #!/usr/bin/sh for index in `ls /tmp/common/*.txt` do echo "$index" done here index is giving full path but in my program i want only file names (not along with whole path) Eg. if in /tmp/common files are a.txt and b.txt den out should be a.txt b.txt ... (6 Replies)
Discussion started by: crackthehit007
6 Replies

5. Shell Programming and Scripting

How do manipulate file path and names

In emacs elisp, there is a handy function called file-name-nondirectory which accepts a path and file name and returns just a file name and extension. There is also a function called file-name-directory which just returns the dire ctory name without the file. How can I implement these same... (2 Replies)
Discussion started by: siegfried
2 Replies

6. Shell Programming and Scripting

Setting path

Hi all, I have a java command in a shell script. When i m executing the command from the prompt its working fine. But when i paste the same command in a shell script and execute the shell script it says path not found. Please help. (5 Replies)
Discussion started by: radhika03
5 Replies

7. UNIX for Dummies Questions & Answers

Help on setting path variable

Hi there, I need help on setting the path variable. How can I set the path variable with Bourne Shell. My scripts goes like this, but did not work. #!/bin/sh PATH=/usr/bin:/usr/ucb:/etc:/export/home/zchen/home export PATH Thanks, Z (4 Replies)
Discussion started by: randomcz
4 Replies

8. UNIX for Dummies Questions & Answers

Setting $PATH for a particular file...????

:) dear members; I am trying to placea directory to keep minor records in particular directories.. rather than just rely on hard links.. I would like to set the $PATH variable so that I can access the directory itself from anywhere; ex./ /tmp or /bin /var... I know how to export enviromental... (4 Replies)
Discussion started by: moxxx68
4 Replies

9. UNIX for Dummies Questions & Answers

Setting path for GCC?

Dear all, I have downloaded the latest version of gcc --- gcc-3.3.1.tar.gz from gnu.org. My Linux distribution is Mandrake 9.0. This was how I installed it: su - passwrd: mkdir /usr/local/src cd /usr/local/src gunzip /tmp/gcc-3.3.1.tar.gz #where I downloaded the file tar xvf... (2 Replies)
Discussion started by: HOUSCOUS
2 Replies
Login or Register to Ask a Question