Script to run a command on all txt files present in a dir structure

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to run a command on all txt files present in a dir structure
# 1  
Old 09-02-2009
Script to run a command on all txt files present in a dir structure


I have a directory structure like the one given below


Now, there are a txt files in each dir and subdir, there is a root.txt
I have to write a script where in i have to run a command called "genrb <filename>" on each of these txt files.

Please help me.
# 2  
Old 09-02-2009
windows or unix? (backslash confused me)
for file in $(find $starting_path -name "root.txt" -type f)
 echo $file ## any command you want to run with each txt file

# 3  
Old 09-02-2009

The command that i have to run has to run when the working directory is where the txt is.

So, a script which traverses through a dir structure and runs the command whenever it finds a .txt would help.
# 4  
Old 09-02-2009
try soemthing like :

for file in $(find $starting_path -name "root.txt" -type f)
 FILE=$(basename $file)
 DIR=$(dirname $file)
 cd $DIR
 echo $FILE ## any command you want to run with each txt file

# 5  
Old 09-07-2009
Thanks a lot. It is working fine now.
One last query.
How can i pass a windows folder path as a param.

this is my func

for file in $(find c:\\temp\\ -name "root.txt" -type f)
genrb.exe $file -d $(dirname $file)

and i run it as

now i want to pass the path i.e. c:\temp as a parameter.
# 6  
Old 09-07-2009
since you are using MKS, I am not sure about it as I never worked on it.
but i think the paths will be understood by MKS automatically.( not sure)

other people can help better in this case.
# 7  
Old 09-07-2009
i was thinking of something like this:

proc main{argv argc}
set path [lindex $argv 0]
for file in $(find $path -name "root.txt" -type f)
genrb.exe $file -d $(dirname $file)
main $argv $argc

and i run it as
C:\temp2> C:\temp\

Logicaly this should work
But this is still giving an error
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to get a variables from two different txt files and need to run a command using that values?

Hi Q1. I have a scenario to run cfsend command,this command will run based on node name,port num,userid and password I was created one file called test.txt and inserted two values,then called those two values from test.txt file that pointed to node place and ran the script it worked fine Now... (10 Replies)
Discussion started by: venuvaka
10 Replies

2. Shell Programming and Scripting

Copying files to new dir structure.

I am trying to figure out a way to script copying specific files from one dir structure to another. I have a dir structure like this: dira/author 1/book 1/file a.epub /book 2/file b.epub /author 2/book 1/file c.epub /author 3/book 1/file d.epub /book 2/file... (2 Replies)
Discussion started by: arcanas
2 Replies

3. Shell Programming and Scripting

Run command on each and every logs of dir

HI i have below command and i want to run it on each logs of each and every Dir. /home/Laco/Al I have sub dir in this folder /home/Laco/Al/04092012/LP/X/*.logs /home/Laco/Al/04092012/LP/Y/*.logs /home/Laco/Al/04092012/LP/Z/*.logs /home/Laco/Al/04092012/LP/P/*.logs I want to run... (5 Replies)
Discussion started by: asavaliya
5 Replies

4. Shell Programming and Scripting

Script to list files not present in audio.txt file

I am having following folder structure. /root/audios/pop /root/audios/jazz /root/audios/rock Inside those pop, jazz, rock folders there are following files, p1.ul, p2.ul, p3.ul, j1.ul, j2.ul, j3.ul, r1.ul, r2.ul, r3.ul And I have a file named as "audio.txt" in the path /root/audios,... (11 Replies)
Discussion started by: gopikrish81
11 Replies

5. Shell Programming and Scripting

Copy files from input file with dir structure

hi, I want to copy files from source directory based on input file (or output of previous command) and i want to have the SAME DIRECTORY STRUCTURE. Note that i will have other files and directories which i dont want to copy to destination. For example, dir source has following content:... (22 Replies)
Discussion started by: dragon.1431
22 Replies

6. Shell Programming and Scripting

Run SED for all index.jsp files across a directory structure.

Hi, I am a novice and require help once again. I have a over 200 file all called index.jsp placed in different directories The following Sed command gives me the data of all included jsp files in index.jsp sed -n -e 's/^.*page="\(*\).*$/\1/p' index.jsp How can I run the above... (6 Replies)
Discussion started by: rajkdutta
6 Replies

7. Shell Programming and Scripting

A script to find dir, delete files in, and then del dir?

Hello!! I have directories from 2008, with files in them. I want to create a script that will find the directoried from 2008 (example directory: drwxr-xr-x 2 isplan users 1024 Nov 21 2008 FILES_112108), delete the files within those directories and then delete the directories... (3 Replies)
Discussion started by: bigben1220
3 Replies

8. UNIX for Dummies Questions & Answers

Cron job to run a command from another dir?

I would like to setup a cron job to run a command from another directory. What is the best way to do this? The cron file is in a directory and the script I want it to run is in another directory. I tried doing this in the cron file: /location/of/command/ But that did not work.... (2 Replies)
Discussion started by: Sepia
2 Replies

9. Solaris

list files .txt and .TXT in one command

Dear experts, In a directory i have both *.TXT and *.txt files. I have a script- for file in `ls *.txt`; do mv $file /tmp/$file How to list both *.txt and*.TXT file in one command so that script will move both .txt or .TXT whatever it find. br//purple (4 Replies)
Discussion started by: thepurple
4 Replies

10. Shell Programming and Scripting

script to go to a different dir to run a commandline prompt in that dir

Hi, I need to know how I'll be able to write a script that can goto a different dir where I don't have access to read,write and execute and also to run a commandline prompt in that dir with one file whose path has to be specified in that command. Will I be able to do this? Any ideas or... (2 Replies)
Discussion started by: ann_124
2 Replies
Login or Register to Ask a Question