Greetings,
How do I batch replace a long string of text with another one?
It’s at the very beginning of the text file.
I need to replace this text with…nothing…I simply have to delete it from these hundreds of files.
Well…I also have some text to remove from the very bottom of the file…
The text I want to remove is the exact same on all the files: they are HTML webpages converted to TXT, so I need to cut all the text that is not the body, such as menu and other.
Alas I can’t reach the original HTML files.
The likes of Visual Studio and other text editors allow you to open multiple files and once and delete lines, but not sure that’s helpful for a large number of files
I cannot think of a “no code” solution. Probably relatively simple to do with Python but one must know the exact patterns you are searching for and what the replacement text is. And of course have to know some Python. Also, most any coding language could do this.
As others have suggested, I would recommend BBEdit. It is an amazing text tool for countless reasons. Its Search and Replace functionality is peerless.
It is also capable of dealing with an entire folder of text files in one swoop. So it could complete your task in a couple of seconds.
No programming. The above site discusses how to set this up. It is a two or three step process.
As others have suggested use sed or awk in a Terminal session. I have to change text like that when dealing with electoral data from my local council. Although I found the GNU version sed better than the default BSD version that comes pre-installed with macOS. (GNU sed has a few more options available when processing repetative patterns.)
Once upon a time I’d have used sed for this, but these days I’d just use python, mostly because the string functions are easier to remember (for me) than sed.
This is the kind of problem that Unix geeks (counting myself as one) dream of when we go on about how command line interfaces are superior to GUIs for “real work”