darkoshi: (Default)
They keep showing that car commercial on TV. The one that starts out with the music sounding like a Star Wars trailer. It feels like sacrilege to me. Apparently this isn't a new thing - there have been other car commercials in the past with Star Wars themes. But I don't remember seeing them, or if I did, they must not have bothered me as much.

Hmm, nope, I haven't seen this one before now. I rather like that one, and it has a funny part too.
On the other hand, this one is even WORSE than the one being shown on TV now. HOW DARE THEY! grrr.

.

I found a grocery store that sells Accent (MSG). All the reviews say it makes "flavor come out" and "makes things taste better". But so far, it doesn't seem that way to me. I tried it on my pasta instead of salt, and ::blech::. Maybe it tastes better when it's added during cooking, or along with other flavors.

.

At work, I noticed a bug in one of the file search utilities I use. I was searching some large XML files for certain element names to verify that all the expected nodes were there, but the count was coming up short in some of the files. The files didn't have line breaks. When I used another tool to add line breaks after each node, and then searched them again, the counts came out correct. So it seems like the utility has a problem searching large files without line breaks.

I thought I would submit a bug report along with a sample file to demonstrate the problem. I stayed late after work to create such a file. I didn't want to submit the original XML file as it had some company-specific things in it. So I started by doing a replace-all to change all instances of one element name to a string of plus signs of the same length. With the file like that, the count of the plus-signs-string still comes out wrong.

Then I did a regex replace-all, to convert *all* other characters in the file to minus signs. That way, the final file still has the same size, and the search string is still in all the same positions as in the original file.

But weirdly, after doing that, the count comes out correct. Even without having added line breaks. So that thwarted me. Tomorrow I may try again, this time not converting the less-than and greater-than characters.

Along the way, I found out that Notepad++ doesn't perform well when using regex to replace nearly all characters in a 10MB sized file. The one time it succeeded at the task, it took 10 minutes to complete. Several other times it locked up or crashed. Then I downloaded UltraEdit, which was able to do the same task in about a minute, maybe less.

Date: 2017-11-18 12:42 pm (UTC)From: [personal profile] andrewducker
andrewducker: (Default)
Using a regex on a large file, I reckon i'd try PowerShell instead. That tends to be able to process things pretty quickly.

Date: 2017-11-20 08:22 am (UTC)From: [personal profile] andrewducker
andrewducker: (Default)
Dead simple.

$myfile = get-content C:\tools\testfile.txt -Raw

(-raw means you get it as one string rather than an array of strings - useful if the regex is going to operate across lines. If it's only going to operate on one line at a time then leave that off)

$myfile -replace "thing","otherthing"
will then do your regex. Replace "thing" with your search regex and "otherthing" with what you want it replaced with.

That'll spit the results out to the command line. When you're happy with it, write it back out to a new file with:

$file -replace "thing","otherthing" | Out-File mynewfile.txt -Encoding utf8

(If you leave off the encoding you'll get utf16 by default. Nobody wants that.)

June 2025

S M T W T F S
1234567
8910 1112 1314
15161718192021
222324 25262728
2930     

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Thursday, June 26th, 2025 07:45 pm
Powered by Dreamwidth Studios