Remove last line from file with Powershell

If you already know that the very last thing of the file is a CRLF you want to get rid of (and you know the encoding too) you can go the quick route: $stream = [IO.File]::OpenWrite(‘foo.txt’) $stream.SetLength($stream.Length – 2) $stream.Close() $stream.Dispose() This is an in-place truncation of the file. It works without reading all the … Read more

Find and replace within a text file using Python

How about this: sed -i ‘s/;/ /g’ yourBigFile.txt This is not a Python solution. You have to start this in a shell. But if you use Notepad, I guess you are on Windows. So here a Python solution: f1 = open(‘yourBigFile.txt’, ‘r’) f2 = open(‘yourBigFile.txt.tmp’, ‘w’) for line in f1: f2.write(line.replace(‘;’, ‘ ‘)) f1.close() f2.close()

Wrap text from bottom to top

I would not recommend using exotic CSS attributes which aren’t even in Chrome & Firefox yet. The best cross-browser solution is to handle this in Javascript when the document loads. Here’s a sketch of how to do that: $(function() { $(“.title”).each(function(i,title) { var width = 0; var originalHeight = $(title).height(); var spacer = $(‘<div style=”float:right;height:1px;”/>’).prependTo(title); … Read more

How can I extract text from a PDF file in Perl?

These modules you can acheive the extract text from pdf PDF::API2 CAM::PDF CAM::PDF::PageText From CPAN my $pdf = CAM::PDF->new($filename); my $pageone_tree = $pdf->getPageContentTree(1); print CAM::PDF::PageText->render($pageone_tree); This module attempts to extract sequential text from a PDF page. This is not a robust process, as PDF text is graphically laid out in arbitrary order. This module uses … Read more

Find text position in PDF file

PyMuPDF can find text by coordinates. You can use this in conjunction with the PyPDF2 highlighting method to accomplish what you’re describing. Or you can just use PyMuPDF to highlight the text. Here is sample code for finding text and highlighting with PyMuPDF: import fitz ### READ IN PDF doc = fitz.open(“input.pdf”) for page in … Read more

Read numbers from a text file in C#

Brannon’s answer explains how to read binary data. If you want to read text data, you should be reading strings and then parsing them – for which there are built-in methods, of course. For example, to read a file with data: 10 10.5 hello You might use: using (TextReader reader = File.OpenText(“test.txt”)) { int x … Read more

How to display text on the screen without a window using Python

It turns out there are two entirely different problems here. To show text over windows, you’ll need to create an undecorated topmost window and chroma key the background. However, this won’t work when there’s a full-screen application running (such as a game). The only reliable way to show text over a full-screen application is to … Read more

counting the number of lines in a text file

Your hack of decrementing the count at the end is exactly that — a hack. Far better to write your loop correctly in the first place, so it doesn’t count the last line twice. int main() { int number_of_lines = 0; std::string line; std::ifstream myfile(“textexample.txt”); while (std::getline(myfile, line)) ++number_of_lines; std::cout << “Number of lines in … Read more