Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have three text files:

years.txt containing:

2003
2004
2005
2006
...

type.txt containing:

cpu
case
ram
hd
...

month.txt containing:

jenuary
february
march
...

Now, I want to create the year folders, inside each of them, create the type folders and into each type, create the days folders.

For example:

2003

    cpu

       jenuary

       february

       ...

    case

       jenuary

       february

       ...

etc.

I must use bin bash script. I think I must read each file, line by line, and store each line into an array... Someone can help me? Thanks a lot

share|improve this question

1 Answer 1

up vote 4 down vote accepted

Here is a script that would do the same

#! /bin/bash

cat years.txt | \
        # Read years.txt line by line. Each line is stored in $folder1.
        while read folder1; do

                cat type.txt | \
                        # Read type.txt line by line. Each line is stored in $folder2.
                        while read folder2; do

                                cat month.txt | \
                                        # Read month.txt line by line. Each line is stored in $folder3.                   
                                        while read folder3; do
                                                # Create/modify $path variable.
                                                path="$folder1/$folder2/$folder3"

                                                # Create the directory.
                                                mkdir -p "$path"
                                        done
                        done
        done

Some help taken from: http://stackoverflow.com/questions/4642191/read-line-by-line-in-bash-script

share|improve this answer
    
Work perfectly! Thanks a lot!!! –  Strider Apr 23 '13 at 15:42
    
Please consider accepting the answer. :) –  green7 Apr 23 '13 at 15:44
    
Done, thanks again. :) –  Strider Apr 23 '13 at 15:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.