loading

Batch, remove text from file?

I have been working on a batch file that will remove half the text from a file and store it somewhere else. I know how to take text out but I don't know how to tell it to take half the text out.

OS: Windows 7


Thanks


sort by: active | newest | oldest
mwrenfro7 years ago
First, how are you defining "half the text" -- the first half of the file, the last half, alternating lines, alternating characters, etc.?

Second, is batch an absolute requirement here? If you're willing to limit yourself to versions of Windows made in the last 10 years or so, you can use Windows Script Host and write things in VBScript or JScript, either of which should offer tons more features than batch commands. If you want something more cross-platform, there's Python and similar languages.

I'll admit I'm no expert in batch, but I expect this sort of task is where you'll run into its limits (I could probably rig something up in a Unix shell script to do this, but I'd end up calling lots of other text-processing tools that won't exist in Windows).

vorlock (author)  mwrenfro7 years ago
I don't really mind which half at all and I would like it to be in batch, so far I have this line of code

find /v /i "Cows" < 1.txt > 2.txt
For slicing and dicing of text files, I use grep, and also gawk (or awk).  These utilities are native to Linux, but here (http://unxutils.sourceforge.net/), you can find versions of them ported to win32. 

I have actually tested these under Windows XP, and Windows 2000, and I'm guessing that they'll work under Windows 7.
XOIIO7 years ago

Dude, I am so sorry that you have to use Windows 7 for batch scripting, if you haven;t found out yet, you will soon that it is very limited.

vorlock (author)  XOIIO7 years ago
Sorry why is it limiting, what is the difference between another OS's terminal/CMD
XOIIO vorlock7 years ago
Windows XP it the best for batch scripting, Windows 7 has a lot of the commands removed, or won't recongnize them. There are more removed than you would think.