How to implement batch processing of reading lines with sensitive characters
This article mainly introduces how to realize the batch processing of reading lines with sensitive characters, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let's take a look at it.
The code is as follows:
@ echo off
Ordinary for+findstr statements ignore lines that begin with a semicolon
:: findstr / n. * after using delims=:, all colons at the beginning of the line are ignored
: and!, &,. Special symbols need to be dealt with.
The following code can extract these sensitive characters accurately
:: solved the problem of the maximum recursion layer of setlocal (this problem occurs when setlocal pairs are nested to deal with more than 15 lines of content)
:: can calculate blank lines
:: code by jm 2006-12-12 thanks 3742668 CMD@XP
Set num=0
For / f "delims="% I in ('findstr / n. * test.txt') do (
Set / a num+=1
Set "str=%%i"
Setlocal enabledelayedexpansion
Echo! num! All right:! struts, "rips"!
Endlocal
)
Pause
Goto: eof
@ echo off
:: when more than 15 lines of content, it will bring the problem of the maximum recursion layer of setlocal
:: code by 3742668 2006-12-11 CMD@XP
@ echo off
Setlocal enabledelayedexpansion
Set num=
For / f "eol= delims="% I in ('findstr. * a.txt') do (
Setlocal DISABLEDELAYEDEXPANSION
Set "tmpstr=%%i"
Setlocal enabledelayedexpansion
Set / a num + = 1
Set "! numb trees
)
For / l% I in (1JI% num%) do echo line%% I:!%% I!
Pause
Exit / b 0
@ echo off
Cannot extract the content with exclamation mark correctly
:: code by jm 2006-12-11 CMD@XP
Set num=0
Setlocal enabledelayedexpansion
For / f "delims="% I in ('findstr / n. * test.txt') do (
Set / a num+=1
Set "str=%%i"
Echo! num! All right:! struts, "rips"!
)
Pause
Goto: eof
@ echo off
The result should be enclosed in quotation marks
:: code by jm 2006-12-11 CMD@XP
Set num=0
:: setlocal enabledelayedexpansion
For / f "delims="% I in ('findstr / n. * test.txt') do (
Set / a num+=1
Set "str=%%i"
Call: display
)
Pause
Goto: eof
: display
Line% num% of echo: "% str:*:=%"
Goto: eof
The content of test.txt
: abc
:: xy
;; ef &
;:
::
&
^
! <
!
%
"
"
'
Test
Abc
Thank you for reading this article carefully. I hope the article "how to achieve batch processing of lines with sensitive characters" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!