Subtracting numbers in two different txt files

Click For Summary
SUMMARY

This discussion focuses on subtracting numbers from two separate .txt files and outputting the results into a third .txt file. Users suggested various tools for this task, including OpenOffice, Python scripting, and VBScript for Windows users. The recommended approach involves reading both files into arrays, performing the subtraction, and writing the results back to a new file. Additional resources, such as a link for reading and writing files in VBScript, were provided for further assistance.

PREREQUISITES
  • Basic understanding of file handling in programming
  • Familiarity with Python scripting or VBScript
  • Knowledge of OpenOffice or LibreOffice for spreadsheet manipulation
  • Access to Google Docs for online spreadsheet solutions
NEXT STEPS
  • Learn Python file I/O operations for reading and writing .txt files
  • Explore VBScript for automating tasks in Windows
  • Investigate OpenOffice Calc functions for spreadsheet calculations
  • Understand how to use Google Sheets for online data manipulation
USEFUL FOR

This discussion is beneficial for programmers, data analysts, and anyone looking to perform arithmetic operations on data stored in text files without using Excel.

Arjani
Messages
20
Reaction score
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?
 
Computer science news on Phys.org
Use OpenOffice then. Or write Python script. Or post your problem giving enough information about OS and tools available to get a meaningful answer.
 
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
 
Last edited by a moderator:
You could download Open or Libre Office, or sign up for a GMail account and use the spreadsheet Google Docs application.
 

Similar threads

Replies
10
Views
2K
  • · Replies 35 ·
2
Replies
35
Views
6K
Replies
4
Views
2K
Replies
7
Views
3K
Replies
15
Views
10K
  • · Replies 8 ·
Replies
8
Views
1K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 31 ·
2
Replies
31
Views
3K
  • · Replies 16 ·
Replies
16
Views
8K
  • · Replies 4 ·
Replies
4
Views
2K