How to redirect output to different directory in BASH?

I have 3 directories named: /home/user/control4 , /home/user/control8 ,/home/user/control16

I have written a script file which has two loops , the first one is running a simulation, producing 3 files named cc1.txt cc2.txt, and cc3.txt and a second loop is for the names of directory

I like to direct cc1.txt, cc2.txt, cc3.txt to /home/user/control4,/home/user/control8 ,/home/user/control16, respectively. What is the exact syntax for doing this in BASH?

Thanks for your help.

My script file look likes this

#!/user/bin/bash
for j in $(4 8 16 ) # loop for directories
do
for i in $(seq 1 3) # loop for simulations  
do
.... produce cc1.txt cc2.txt cc3.txt 
done

How to output the three files to the respective directories? something like /home/user/control$j/cc$i.txt?

done

Answers


for j in /home/user/control{4,8,16}
do
    for i in cc{1,2,3}.txt
    do
        produce "$j/$i"
    done
done

That will produce nine files. If you want one file per directory for a total of three files, some math might do the trick.

for i in {1..3}
do
    produce "/home/user/control$((2*2**i))/cc$i.txt"
done

cat cc$i.txt > /home/user/control$j/cc$i.txt

Need Your Help

How to replace text in a column (inside a table) with Javascript without any ID

javascript html replace

The code below shows a rendered HTML (from Compiled ASP .Net code). I would not be able to make any changes to it including adding new attributes like ID.

Mysterious “errno 150” Mysql.connector python while creating bunch of tables

python mysql connector errno

So here is the problem, I have a single column in a single table that I refer to all foreign keys from other tables. I double-checked all the keys, they are all INT(11), and the column I refer to is

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.