搜索一个文本文件,并只发送大于某个绝对值的数字到文本文件? [英] Searching a text file and sending only numbers greater than a certain absolute value to text file?
问题描述
ksdf 0 0 -4
$ b我有一个我正在寻找的文本文件
$ bas7d:S:asf 0 0 -4
kc:S:cd3 0 0 -2
asdk:S:s 0 0 6
lasd:S:dd 0 0
目前我的具体问题是搜索第一个和第四个令牌的文件。如果第四个标记是一个数字,一切都发送正常,但是当第四个标记是空白的(就像在我的例子中的第五行),代码根本不起作用。你可以看到我想在 %% B
变量中找到空白时返回三个星号。
:感谢用户LotPings,我使用 findstr
命令来抓取只包含子字符串的字符串:S:
只是为了澄清为什么在那里。 (即在我的例子中的第1行不会被抓取。)
我正在使用:
<$ p ('Findstr / b / r / c:[^] *:S中的/ Ftokens = 1,4%% A)$ p> setlocal enabledelayedexpansion
:print.log)do(
set space =%% B
if!space!==echo %% A ^ * ^ * ^ *>> new.txt
)
出口
@ECHO OFF
SETLOCAL EnableExtensions EnableDelayedExpansion
> new.txt(
For / Ftokens = 1,4 %% A in('Findstr / b / r / c:[^] *:S:print.log')do(
setspace = %% B
if! (echo %% A ^ * ^ * ^ *)else(echo %% A %% B)
)
)
type new.txt
暂停
I have a text file that I am searching through that looks like:
ksdf 0 0 -4
as7d:S:asf 0 0 -4
kc:S:cd3 0 0 -2
asdk:S:s 0 0 6
lasd:S:dd 0 0
At the moment my specific problem is when searching the file for the 1st and 4th tokens. If the 4th token is a number everything sends fine, but when the fourth token is blank (as on the 5th line in my example) the code simply doesn't work. You can see I want to return three asterisks when it finds a blank in the %%B
variable.
NOTE: Thanks to the user, LotPings, I'm using the findstr
command to grab only lines beginning with strings containing the substring :S:
just to clarify why that's there. (Ie. line 1 in my example wouldn't be grabbed.)
I'm using:
setlocal enabledelayedexpansion
For /F "tokens=1,4" %%A in ('Findstr /b /r /c:"[^ ]*:S:" print.log') do (
set space="%%B"
if !space!=="" echo %%A ^*^*^* >> new.txt
)
exit
@ECHO OFF
SETLOCAL EnableExtensions EnableDelayedExpansion
>new.txt (
For /F "tokens=1,4" %%A in ('Findstr /b /r /c:"[^ ]*:S:" print.log') do (
set "space=%%B"
if "!space!"=="" (echo %%A ^*^*^*) else (echo %%A %%B)
)
)
type new.txt
pause
这篇关于搜索一个文本文件,并只发送大于某个绝对值的数字到文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!