Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the batch processing of finding the contents of even rows

Shulou Source: shulou.com Published: 2022-06-03 08:15:28 09月20日 Update

This article will explain in detail how to find the batch processing of even-numbered lines. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

The code is as follows:

@ echo off

:: find even-numbered lines

::

Set nasty 0

For / f "delims=" I in (test.txt) do set / a naughty 1

For / l%% I in (1 dint 2% n%) do (

Findstr / n "." Test.txt | findstr / r "^% I:" > tmp.txt

)

For / f "tokens=1* delims=:" I in (tmp.txt) do echo j > > end.txt

Del tmp.txt

Start end.txt

Goto: eof

Another option

No temporary files are generated, and the speed is much faster

:: if you use. * in findstr, "ECHO is off" is displayed in the position of the blank line.

:: if you use., blank lines will not be printed

:: code by jm CMD@XP 2006-7-29

@ echo off

Cd. > result.txt

Setlocal enabledelayedexpansion

For / f "tokens=1* delims=:"% I in ('findstr / n "." test.txt') do (

Set num=%%i

Call: mod

If! mod! Equ 0 echo j > > result.txt

)

Start result.txt

Goto: eof

: mod

Set / a mod=%num%%%2

Goto: eof

With a little modification of the previous code, the blank lines in the text can be removed.

@ echo off

Cd. > tmp.txt

For / f "tokens=1* delims=:" I in ('findstr / n "." test.txt') do (echo j > > tmp.txt)

Cd. > result.txt

:: when the blank line in the text is some other unknown code (this happens when copied from a web page)

:: "ECHO is off" is displayed at the blank line. The following code deletes this line

Findstr / v "\" tmp.txt > > result.txt

Del / q tmp.txt

This is the end of this article on "how to find batches of even-numbered lines". I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, please share it for more people to see.

Tags: Content blank line code even number article text more status good practical location situation file article scheme knowledge web page speed previous reference Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Information NVidia Shulou Technology Docker