If you're comfortable compiling C++, this should do the trick. Basically, I put each line of the file in a vector, and output it to a new file by using a reverse iterator.
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
int main()
{
std::vector<std::string> fileLines;
std::string currLine;
std::ifstream inFile("input.txt");
if (inFile.is_open())
{
while (inFile.good())
{
std::getline(inFile, currLine);
fileLines.push_back(currLine);
}
inFile.close();
}
else
{
std::cout << "Error - could not open input file!\n";
return 1;
}
std::ofstream outFile("output.txt");
if (outFile.is_open())
{
std::vector<std::string>::reverse_iterator rIt;
for (rIt = fileLines.rbegin(); rIt < fileLines.rend(); rIt++)
{
outFile << *rIt;
}
outFile.close();
}
else
{
std::cout << "Error - could not open output file!\n";
return 1;
}
return 0;
}
If the output file is missing line breaks between the lines, then change the outFile << *rIt;
to be outFile << *rIt << "\r\n";
so a line break is added (omit the \r
if you're on Unix/Linux).
Disclaimer: I have not tested this code (I wrote it real quick in Notepad), but it looks viable.
Related (but not duplicate): How to reverse a text file on Windows
– Peter Mortensen – 2019-07-14T12:35:33.560Meaning you want the numbers on the left margin to count down, or you want the actual content of your file to be reversed? – Maxpm – 2011-09-02T12:30:31.137
2@Maxpm Actual content of the file to be reversed. – Danpe – 2011-09-02T12:40:55.543
possible duplicate of Reverse line order in Notepad++
– Franck Dernoncourt – 2014-02-28T15:49:46.090