1

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

0

2 Answers 2

2

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
8
  • 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 Commented Jun 13, 2013 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? Commented Jun 13, 2013 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;) Commented Jun 13, 2013 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 Commented Jun 13, 2013 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; Commented Jun 13, 2013 at 20:42
0
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.

1
  • 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 Commented Jun 13, 2013 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.