multiple groups of files processing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting multiple groups of files processing
# 1  
Old 12-02-2010
multiple groups of files processing

I have five directories, dir1 to dir5
for each directory, I have all same number-named folders. There are four types of folders, {1..10}, {20..30}, { 40..50}, {60..70}

Now for each types of folder, I will do the same thing, here is the code
Code:
for i in {1..5}
do
cd dir$i

 mkdir temp1
 for j in {1..10}
  do 
   cd $j 
    cp test.txt ../temp1/$j.txt.dir$i
   cd ..
  done

  echo "done with 1 to 10"

## then repeat from "mkdir..." for {20..30} and so on...
# each mkdir for {10..20} or {20..30}... would be different, such as temp2...

cd ..
done

Is there any way I can loop this? Thanks a lot!
# 2  
Old 12-02-2010
Just repeat the same pattern you've written twice already.
Code:
for i in {1..5}
do
cd dir$i

 for k in {1..10}
 do
  mkdir temp$k
  for j in {1..10}
   do 
    cd $j 
     cp test.txt ../temp$k/$j.txt.dir$i
    cd ..
   done
  done

  echo "done with 1 to 10"

## then repeat from "mkdir..." for {20..30} and so on...
# each mkdir for {10..20} or {20..30}... would be different, such as temp2...

cd ..
done

Quote:
Is there any way I can loop this? Thanks a lot!

Last edited by Scott; 12-02-2010 at 07:21 PM..
# 3  
Old 12-03-2010
Thanks for the response. Maybe I should be more clearer about the data structure.

in each of the directory, dir1, or dir2, etc, all contains 40 folders (1, 2, 3, .., 10, 20, 21, 22, 23, .., 29, 30, 40, 41, 42, .., 49, 50, 60, 61, 62, ..,69, 70). These four criteria need to process independently but doing the same process, since eventually I need to cat files in each criteria and generate four files eventually.

Thanks for the help

Last edited by ksgreen; 12-03-2010 at 05:02 PM..
# 4  
Old 12-03-2010
I'm afraid that explanation's just left me more confused than ever. That's 50 folders.

How about:

Code:
mkdir -p dir1/{1..20}
mkdir -p dir2/{21..30}
mkdir -p dir3/{40..50}
mkdir -p dir4/{60..70}

Also note that the {1..100} operator has limits. If you start jamming more than a few hundred into a commandline or a for statement, you'll run out of arguments.
# 5  
Old 12-03-2010
Thank you. this would be easier but there are several reasons to keep the current structure...

So my question is, without changing the current structure, any better way to loop more efficiently? now I run every criteria's folders repeatedly and would be nice to loop it better
# 6  
Old 12-03-2010
"better" as in what?

I still can't tell what you're even asking me to do.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Processing multiple files (environment setting)

Hello I posted on here a while ago about processing multiple files within a script. See original post below: I have a program cfxfrwb which is designed to remove headers from reports files. The cfxfrwb is located in the following directory /u01/efin/v40/live/bin I run the program against... (8 Replies)
Discussion started by: captainrhodes
8 Replies

2. Shell Programming and Scripting

Processing multiple files

Hello I have a program cfxfrwb which is designed to remove headers from reports files. The cfxfrwb is located in the following directory /u01/efin/v40/live/bin I run the program against a single report file in the temp directory and it does it's job../cfxfrwb... (2 Replies)
Discussion started by: captainrhodes
2 Replies

3. Shell Programming and Scripting

Passing multiple files to awk for processing in bash script

Hi, I'm using awk command in bash script. I'm able to pass multiple files to awk for processing.The code i can use is as below(sample code) #!/bin/bash awk -F "," 'BEGIN { ... ... ... }' file1 file2 file3 In the above code i'm passing the file names manually and it is fine till my... (7 Replies)
Discussion started by: shree11
7 Replies

4. Shell Programming and Scripting

Processing multiple files awk

hai i need my single awk script to act on 4 trace files of ns2 and to calculate througput and it should print result from each trace file in a single trace file. i tried with the following code but it doesnt work awk -f awkscript inputfile1 inputfile2 inputfile3 inputfile4>outputfile ... (4 Replies)
Discussion started by: sarathyy
4 Replies

5. UNIX for Dummies Questions & Answers

Users in multiple groups?

Happy Thanksgiving Everyone!! I have a question about adding users to multiple groups. Thanks in advance Using Red Hat and here are the issues: Example: Users: Bob Mark Groups: SystemsAnalysts BusinessAnalysts If I am adding a user Bob to both groups (SystemsAnalysts and... (2 Replies)
Discussion started by: hansokl
2 Replies

6. UNIX for Dummies Questions & Answers

Multiple groups in directory / file permissions

Hi I need to permit one group to have r-x permissions on all files in a directory and another group to have just read access, im confused how to do this as if i set the 'Other' permission class as read access then all users will have access to them. So basically i have a directory which the... (2 Replies)
Discussion started by: m3y
2 Replies

7. UNIX for Dummies Questions & Answers

How to add user to multiple groups

hi all i am new to solaris how to add a user to multiple(secondary) groups. user :anna Groups : delhi ,mumbai,pune i need like this in cat /etc/group delhi::anna mumbai::anna pune::anna i tried using usermod -a -G hyd anna that does int work how to delete user from group... (3 Replies)
Discussion started by: kalyankalyan
3 Replies

8. UNIX for Dummies Questions & Answers

single output of awk script processing multiple files

Helllo UNIX Forum :) Since I am posting on this board, yes, I am new to UNIX! I read a copy of "UNIX made easy" from 1990, which felt like a making a "computer-science time jump" backwards ;) So, basically I have some sort of understanding what the basic concept is. Problem Description:... (6 Replies)
Discussion started by: Kasimir
6 Replies

9. UNIX for Dummies Questions & Answers

Multiple excel files processing on unix

Hi all, I am faced with a rather unusual problem regarding interaction between NT and UNIX. I am using an ETL (Extract-Transform-Load) tool on unix that has the capability to read .xls files. So, when I FTP an excel (.xls) file from a windows server to unix and attempt to read it with this... (3 Replies)
Discussion started by: ucode_2482
3 Replies

10. Shell Programming and Scripting

Processing Multiple Files

Hello Everyone, I am new to scripting and confused with how to do this efficiently. I am trying to use AWK to do this. I have a lot of files in a folder which has the data of my throughput measurements in two columns i.e. Serial # and Throughput. like this 177.994 847.9 178.996 ... (1 Reply)
Discussion started by: hakim
1 Replies
Login or Register to Ask a Question