Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report