Find the answer to your Linux question:
Results 1 to 7 of 7
I'm trying to create a script that basically pulls all of the information from 5 different files from 5 different directories and saves the information into one file. Then pulling ...
  1. #1
    Just Joined!
    Join Date
    Jun 2010
    Posts
    5

    Linux Help

    I'm trying to create a script that basically pulls all of the information from 5 different files from 5 different directories and saves the information into one file. Then pulling some information from this newly saved file along with some other files located in the same directory to one final file (They are all .txt files). I've tried many scenarios but I haven't been able to figure out how to do it. Can anyone help? Thanks!

  2. #2
    tpl
    tpl is offline
    Linux User
    Join Date
    Jan 2007
    Location
    cleveland
    Posts
    452
    welcome to the forum

    you're not giving us much to go on--

    cat /dir_1/file /dir_2/file /dir_3/file /dir_4/file /dir_5/file >>big_file

    should collect them all: but then what?
    the sun is new every day (heraclitus)

  3. #3
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Assuming you need to filter the files somewhat:

    Code:
    cat /dir1/file /dir2/file /dir3/file /dir4/file /dir5/file | filter1 >/otherdir/first_results
    cat /otherdir/first_results /otherdir/file1 ... /otherdir/fileN | filter2 >/otherdir/final_results
    There are many ways to do what you want, and it depends upon what you are trying to accomplish and how you need to filter the data to get what you need. A filter can be as simple as a grep/egrep regular expression, to a full awk/grep/sed script.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  4. #4
    Just Joined!
    Join Date
    Jun 2010
    Posts
    5

    Question More Info

    I have five different directories: Houseware, Electronics, WomenApp, MenApp, ChildApp. Within each directory there is a file called Sales. I need all the information from those files to be saved into the preceding directory of President to be called SalesFinal.

    Also in the President directory are two other files called Phonebook and Personnel. I would all three files to be put into one file called Report. But I want to use only some of the information. The Phonebook file has just a name and number (John Doe (TAB)(604-555-1234). The Personnel file has name position and department (John Doe (TAB)Associate (TAB)(Housewares). The output of SalesFinal should be name and sales amount (John Doe $12,342 with the Total of each file at the bottom).

    The final output of Report should look something like this:
    John Doe XXX-XXX-1234 Associate Housewares $12,342
    The last five lines should have the Totals for each dept (Total Elect $42,231)
    The phone numbers of all the employees have the same area code and starter numbers (604-555). I just need the last four.

    And then from that Report I would like to use only the employees who have the highest sales amount from each department and the totals for each department to be saved into WeeklyReport.

    Can this be done? Or did I overcomplicate things?

  5. #5
    Just Joined!
    Join Date
    Jun 2010
    Posts
    5
    I got the SalesFinal file to work just like I want it using the above command you supplied earlier THANKS!

    Now to work on the others.

  6. #6
    Linux Newbie
    Join Date
    Oct 2008
    Posts
    140
    This looks an awful lot like a homework question, which are disallowed by the form rules.

  7. #7
    Just Joined!
    Join Date
    Jun 2010
    Posts
    5
    Actually, I'm using this simplistic method to create more complicated files later on.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...