Question

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

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top