ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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..
I have another doubt , as a follow up to the same script .. 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 do something similar to assign some path to variables representing the directories , each time when i run the script?
This could be a job for make.
You don't want to regenerate every time if the
data hasn't changed. (do you?)
Code:
# this will do COMMAND
# on a list on all .txt files in
# the directory outputing to a .lis
# file
#
# it genrates the list of txt files so you
# don't have to worry about them
include depend.mk
COMMAND = echo
COMMAND = cp
# change the suffixes if you don't like
# .txt and .lis
# ==============
.SUFFIXES: .txt .lis
OUTFILES = $(DATA:txt=lis)
.txt.lis:
$(COMMAND) $< $@
all:$(OUTFILES)
rm depend.mk
# automagically generate list of txt files
# ========================================
depend.mk:
@echo DATA = *.txt > $@
the indents are TABs.
copy to file called Makefile
then type make.
or maybe not?
Last edited by bigearsbilly; 01-31-2005 at 07:47 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.