![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Jan 2005
Posts: 5
Rep Power: 0
![]() |
Bash script to access all files in a directory
Hi .. I am a new bie in writing scripts, so this doubt may be a simple one.
I am trying to apply a parsing program to a set of input files in a directoy. How can i access all the files from a source directory , one by one and to write the output files with another name to some directory ? i.e my exe file is a.out I have input files 1.txt,2.txt .. in one directory. I need this cmd line ./a.out <inputfilename> > <outputfilename> , on all input files. can i write a loop to get all files like this ? right now i am writing the same line again and again to apply to all files.. Plz post ur suggestions. Thank u Shinni |
|
|
|
|
|
#2 |
|
Programming Guru
![]() ![]() ![]() |
in your script, have ls -lstr > file
then have a while loop that gets fed file inside the while loop... assign a variable to the 10th position in that file (the filename of the current file in your dir) - you can do this with awk then, still in the loop, call your a.out $curFile > newFile
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Jan 2005
Posts: 5
Rep Power: 0
![]() |
Re :Bash script to access all files in a directory Reply to Thread
Thank u .. I had posted this doubt at one more forum n i got the following steps also..
This also works. #!/bin/bash cd <input_file_directory> for file in `dir -d *` ; do <exeFile with full path> "$file" <output_file_path/"$file".out> done I have another doubt , as a follow up .. If i need to change this input directory and output directory to test different data sets, what should i do ? Now, i hav specified SourceDir and DestDir within the program. Can i pass command line arguements or soemthing like that to assign some path to variables representing the directories ? Thank u Shinni |
|
|
|
|
|
#4 |
|
Programming Guru
![]() ![]() ![]() |
yes, parameters will work fine.
$0 = program name $1 = 1st parameter $2 = 2nd parameter
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#5 | |
|
Newbie
|
Quote:
./a.out <infilename> <outfilename>
__________________
Signed, Magyarkid |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|