Find the answer to your Linux question:
Results 1 to 7 of 7
Hi, I will need a script to consolidate 2 files into 1 file and need to sum up one of the fields. Sample file below FILE1 lea 200 Y testing1 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2014
    Posts
    1

    script on how to consolidate 2 files into 1


    Hi,

    I will need a script to consolidate 2 files into 1 file and need to sum up one of the fields. Sample file below

    FILE1
    lea 200 Y testing1 country1
    dan 300 Y testing2 country2

    FILE2
    lea 300 Y testing1 country1
    bill 100 Y testing1 country1
    dan 50 N testing2 country2

    FILE3 (output file)
    lea 500 Y testing1 country1
    dan 300 Y testing2 country2
    bill 100 Y testing1 country1
    dan 50 N testing2 country2

    Hope someone can help me.

    Thanks.

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,440
    Hi and welcome

    This seems fairly basic, is it maybe homework?
    What have you tried so far?
    You must always face the curtain with a bow.

  3. #3
    Linux Engineer docbop's Avatar
    Join Date
    Nov 2009
    Location
    Woodshed, CA
    Posts
    949
    Quote Originally Posted by Irithori View Post
    Hi and welcome

    This seems fairly basic, is it maybe homework?
    What have you tried so far?
    should talk to his cat.
    A lion does not lose sleep, over the opinion of sheep.

  4. $spacer_open
    $spacer_close
  5. #4
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,440
    This is one way, but the solution I have in mind doesnt need a computer cat. Rather one that runs over the keyboard

    Sent from my GT-I9505 using Tapatalk
    You must always face the curtain with a bow.

  6. #5
    Linux Engineer docbop's Avatar
    Join Date
    Nov 2009
    Location
    Woodshed, CA
    Posts
    949
    Quote Originally Posted by Irithori View Post
    This is one way, but the solution I have in mind doesnt need a computer cat. Rather one that runs over the keyboard

    Sent from my GT-I9505 using Tapatalk
    cat's can bring things together with the right (re)direction. <grin>
    A lion does not lose sleep, over the opinion of sheep.

  7. #6
    Linux Newbie
    Join Date
    Mar 2014
    Posts
    133
    sounds like sending the output of one file to a new file, then appending another file to that new file?

    File 1 > File3
    File2 > append to File 3

    If I'm reading right that is...

  8. #7
    Linux Guru
    Join Date
    Oct 2007
    Location
    Tucson AZ
    Posts
    3,190
    sounds like sending the output of one file to a new file, then appending another file to that new file?
    Doesn't look that simple to me but the OP may just have typos. I'm not really sure what the OP is trying to accomplish. FILE1 has an entry 'lea200'. FILE2 has an entry 'lea300'. FILE3 then adds the two numbers and the entry is 'lea500'. Then FILE1 has an entry 'dan50'. FILE2 has an entry 'dan300' and FILE3 has these entries repeated, not added together as the previous entry. So how does the OP determine which numbers are added and which not? Is it just random??

Posting Permissions

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