The task was to create a set of folders say 1,2,3,4 and in each of these four folders create four sub folders.
Thus 16 folders were to be created and in each of these 16 folders a common set of files were to be copied.
I used c shell scripting to do the job. I needed two lists. One list for primary folders
list1:
1
2
3
4
and another list for the subfolders.
list2:
5
6
7
8
It worked as:
-------------------
bash-3.2$ csh
r410comp2%
r410comp2%foreach f (`cat ../list1`)
foreach? echo $f
foreach? mkdir "$f"
foreach? cd "$f"
foreach? foreach g (`cat ../../list2`)
foreach? echo $g
foreach? mkdir "$f"_"$g"
foreach? cd "$f"_"$g"
foreach? cp /home/kjoshi/W/work/complex/2_ion/umbrella/6/6_75/u_6_75.in .
foreach? cp /home/kjoshi/W/work/complex/2_ion/umbrella/6/6_75/amber11_intel_ref_md .
foreach?cp /home/kjoshi/W/work/complex/2_ion/umbrella/6/6_75/2_ion.inpcrd .
foreach?cp /home/kjoshi/W/work/complex/2_ion/umbrella/6/6_75/2_ion.prmtop .
foreach?cp /home/kjoshi/W/work/complex/2_ion/umbrella/6/6_75/dist.RST .
foreach?cd ..
foreach?end
foreach?cd ..
foreach?end
---------------
Thus it created folders with names like
main folder : 4
subfolders: 4_5
4_6
4_7
4_8
and so on for other main folders.
All these subfolders contain the required files copied from some location
I then had to rename a particular file in each of these subfolders in particular format.
File to be renamed :u_6_75.in
to: u_4_5.in, u_4_6.in etc
So I did this:
-----------------
r410comp2% foreach f (`cat ../list1`)
foreach? echo $f
foreach? cd "$f"
foreach? foreach g (`cat ../../list2`)
foreach? echo $g
foreach? cd "$f"_"$g"
foreach? mv u_6_75.in u_"$f"_"$g".in
foreach? cd ..
foreach? end
foreach? cd ..
foreach? end
---------------
So these files were renamed as u_4_5.in, u_4_6.in etc.
Worth time saving
Comments
Post a Comment