Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

I need to automate a process using a script and generate output files similar to the name of the input files but with some additions to it.

my process is a Java code. two input arguments and two output arguments.

java #process_class# abc.txt abd.txt abc.1.out abd.a.out

If i want to iterate this for the set of text files in my folder how can i do this

share|improve this question

2 Answers 2

up vote 1 down vote accepted

If you have the files a.txt, b.txt, and c.txt in the directory in which this is run, this program will output a_2.txt, b_2.txt, and c_2.txt with foo appended to each (replace the foo line with your processing commands).

for f in *.txt;
    do f2=${f%.*}_2.txt;
    cp $f $f2;
    echo "Processing $f2 file...";
    echo "foo" >> $f2; # Your processing command here
done
share|improve this answer
    
thank you sir. my process is a Java code. two input arguments and two output arguments. java <process> abc.txt abd.txt abc.1.out abc.a.out If i want to iterate this for the set of text files in my folder how can i do this – Vignesh Jun 13 '13 at 20:16
    
Can you clarify what you mean so I can help you out? Do you want to run the java process on every file in the directory? Can you type out a few of the iterations? – 22222222 Jun 13 '13 at 20:26
    
yea. My folder has twenty text files. a1,a2 to a10 and b1,b2 to b10. my java program takes each of a files and b files and generates output. Iter1: input: a1.txt, b1.txt output: a1.processed.1.txt, b1.processed.1.txt Iter2: Input a2.txt, b2.txt Output: a2.processed.2.txt, b2.processed.2.txt This has to go on for all twenty files, that is ten iterations. This is given to a java program as java #program# a1.txt b1.txt a1.processed.1.txt b1.processed.1.txt. Instead of running this java script individually, i am iterating it using a script. (contd;) – Vignesh Jun 13 '13 at 20:34
    
for entry in ls a*.txt;do for extry1 ls b*.txt;do java #process# $entry $entry1 <automated output file names> <automated output file names> done done In the place of <>s i need to automate the file names – Vignesh Jun 13 '13 at 20:35
    
for num in $(seq 1 10); do java program a$num.txt b$num.txt a$num.processed.$num.txt b$num.processed.$num.txt; done; – 22222222 Jun 13 '13 at 20:42
VAR="INPUTFILENAME"
# One solution this does not use the VAR:
touch INPUTFILENAME{1,2,3,4,5,6,7,8,9,10}
# Another
for i in `seq 1 20` ; do
  touch "${VAR}${i}"
done

And there are several other ways.

share|improve this answer
    
thank you sir. my process is a Java code. two input arguments and two output arguments. java <process> abc.txt abd.txt abc.1.out abc.a.out If i want to iterate this for the set of text files in my folder how can i do this – Vignesh Jun 13 '13 at 20:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.