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 batches display lines with only a specified number of characters

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces how to display lines with only a specified number of characters in batch processing, which is very detailed and has a certain reference value. Friends who are interested must finish reading it!

The code is as follows:

@ echo off

Goto begin

Parameter 1: text file name

Parameter 2: the number of characters of the lines to be displayed (save)

For example, to print a line with 4 characters in a.txt:

Print.bat a.txt 4

Or drag and drop the file you want to process directly onto the script file and follow the prompts.

Very efficient

: begin

Setlocal ENABLEDELAYEDEXPANSION

Set var=%2

If "% var%" = "" set / p var= enter the number of characters of the line to display:

For / l%% I in (1JI% var%) do set stringers.

Findstr / x str% 1

Pause > nul

Goto: eof

@ echo off

:: displays a line of text with only 4 characters

:: test.txt has only pure letters, no spaces, no blank lines

:: because it is a full-text analysis, it is inefficient

:: code by jm 2006-8-14

For / f% I in (test.txt) do (

Set str=%%i

Set var=%%i

Call: loop

Set num=0

)

Pause

Goto: eof

: loop

Set var=%var:~0,-1%&& set / a num+=1

If not "% var%" = "" goto loop

If num% equ 4 echo str%

Goto: eof

@ echo off

:: it is more efficient to judge by inserting characters at the beginning and end.

:: suitable for situations with spaces in the line

:: if you do not insert characters, but only judge the situation of the fifth character, you will make an error

:: code by 3742668

Setlocal ENABLEDELAYEDEXPANSION

For / f "delims="% I in (test.txt) do (

Set str=b%%ie

If not "! str:~5,1!" = "" if "! str:~6,1!" = "" echo. % I

)

Pause

Goto: eof

The above is all the content of the article "how to display lines with only a specified number of characters in batches". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

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