Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Subtracting numbers in two different txt files

  1. Jan 14, 2013 #1
    I have two .txt files with a bunch of numbers in them, below each other, like this:

    File 1:

    3
    4
    5

    File 2:

    1
    2
    1


    Now I want to subtract the numbers in file 2 from the numbers in file 1 and get the results in a new .txt file:

    File 3:

    2
    2
    4

    Very simple. I was going to do it in Excel, but I don't have that right now. Does anyone know another easy way?
     
  2. jcsd
  3. Jan 15, 2013 #2

    Borek

    User Avatar

    Staff: Mentor

    Use OpenOffice then. Or write Python script. Or post your problem giving enough information about OS and tools available to get a meaningful answer.
     
  4. Jan 15, 2013 #3
    If you've got Windows, try VBScript. Read the 2 files into an array, add the elements of the arrays and write the results back out. Here's a link showing how to read and write files: http://easyprograming.com/index.php/vb-script/13-open-an-existing-text-file-in-vb-script [Broken]
     
    Last edited by a moderator: May 6, 2017
  5. Jan 20, 2013 #4

    MATLABdude

    User Avatar
    Science Advisor

    You could download Open or Libre Office, or sign up for a GMail account and use the spreadsheet Google Docs application.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook