Computing.Net > Forums > Unix > simple script help

simple script help

Reply to Message Icon

Original Message
Name: gpatel
Date: May 5, 2005 at 08:49:52 Pacific
Subject: simple script help
OS: UNIX
CPU/Ram: 512
Comment:

This is very simple script. I am not a guru at unix just start using it so need some help from you gurus.

This is my Problem
I have this folder w/ lots of file. now lets say i have a file name MyFile.txt
I have a program to run this file
so this is how i run it
program MyFile > MyFilenew.txt
I just wanted to automatically grab the file w/ .txt extension and run it by just typing program
this is how i set up my script
# !/bin/csh -f
cd /myDir
program MyFile > Myfilenew.txt

-----
i dont want to go in the this script and change MyFile all the time. this My File changes everytime i do something new. but extension stay the same as .txt

can some help w/ this. thanks a lot
Gaurav

thanks,
Gaurav


Report Offensive Message For Removal


Response Number 1
Name: willtx56
Date: May 5, 2005 at 14:29:47 Pacific
Reply: (edit)

This is where is started in Unix commands

https://portal.informatics.scitech.sussex.ac.uk/support/sitedocuments/unix.aspx

Biostar NF3250GB
6800GT BFG
Seagate 200 gig
LanBoy/550W Antec
Audigy 2
XP Professional


Report Offensive Follow Up For Removal

Response Number 2
Name: cdac1000
Date: May 6, 2005 at 07:13:47 Pacific
Reply: (edit)

#!/bin/ksh

cd /directory_name

for element in `ls *.txt`
do
programName $element > "$elementNEW.txt"
done

what this will do is, generate an a list of entries of all files containg .txt extension, and then process them with you program, and will put the output in file, using the fileprocessedNEW.txt convention.

Is this what ur looking for?


Report Offensive Follow Up For Removal

Response Number 3
Name: gpatel
Date: May 6, 2005 at 13:27:43 Pacific
Reply: (edit)

thanks a lot cdac..

thanks,
Gaurav


Report Offensive Follow Up For Removal

Response Number 4
Name: Dlonra
Date: May 6, 2005 at 18:37:27 Pacific
Reply: (edit)


needs to be
programName $element > "${element}NEW.txt"


Report Offensive Follow Up For Removal

Response Number 5
Name: gpatel
Date: May 7, 2005 at 10:45:48 Pacific
Reply: (edit)

thank you very much guys..
is there any way i dont have use cd
what i am saying.. there are 16 files under 3 folders. so i have to go and change and do cd and put the right path name.

In details

lets say i have File1 File2 File3
in File1 i have 4 folders
in File2 i have 4 Folders
and same with File3

now, to use this program i have to go and say cd to File1 then cd to File2

is there any way to automate this and program will go thru all the folders (File1 , File2 and File3)

again Thank you very much for you help

thanks,
Gaurav


Report Offensive Follow Up For Removal


Response Number 6
Name: hismail
Date: May 25, 2005 at 06:54:18 Pacific
Reply: (edit)

Try this:
#!/bin/ksh
for f in $(find dirname -type f -name filename);do
cd $(dirname $f);programName $element > "${element}NEW.txt;cd -;done


Report Offensive Follow Up For Removal






Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: simple script help

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 6 Days.
Discuss in The Lounge