我有一位女士给我发了电话号码。它们以凌乱的方式发送。每次。所以我想从 Skype 复制她的整个消息,并让一个批处理文件解析保存的 .txt 文件,只搜索 10 个连续的数字。
例如她发给我:
Hello more numbers for settings please,
WYK-0123456789
CAMP-0123456789
0123456789
Include 0123456789
This is an urgent number: 0123456789
TIDO: 0123456789
Send to> 0123456789
这真是一团糟,唯一不变的是 10 位数字。所以我想要 .bat 文件来了解如何扫描这个怪物并给我留下如下内容:
例如我想要的:
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
我在下面尝试了 this
@echo off
setlocal enableDelayedExpansion
(
for /f %%A in (
'findstr "^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" yourFile.txt'
) do (
set "ln=%%A"
echo !ln:~0,9!
)
)>newFile.txt
不幸的是,它仅在每行的开头以 10 位数字开头时才有效,并且在 10 位数字位于行的中间或末尾的情况下对我没有帮助。
最佳答案
鉴于 10 位数字是文件每一行中的第一个数字部分(让我们称之为 numbers.txt)在任何其他数字之前,您可以使用以下内容:
@echo off
setlocal EnableExtensions EnableDelayedExpansion
rem // Define constants here:
set "_FILE=.\numbers.txt"
set /A "_DIG=10"
rem // The first delimiter is TAB, the last one is SPACE:
for /F "usebackq tokens=1 delims= ^!#$%%&'()*+,-./:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^^_`abcdefghijklmnopqrstuvwxyz{|}~ " %%L in ("!_FILE!") do (
set "NUM=%%L#"
if "!NUM:~%_DIG%!"=="#" echo(%%L
)
endlocal
exit /B
这利用了 for /F 及其 delims 选项字符串,其中包括除数字以外的大多数 ASCII 字符。您可以扩展 delims 选项字符串以包含扩展字符(代码大于 0x7F 的字符);确保 SPACE 是指定的最后一个字符。
这种方法可以像这样从一行中提取 10 位数字:
garbage text>0123456789_more text0123-end
但是如果一行看起来像这样就会失败,所以当第一个数字不是 10 位数字时:
garbage text: 0123 tel. 0123456789; end
这是基于上述方法的综合解决方案。 for/F 的delims 选项的字符列表会在此处自动创建。这甚至可能需要几秒钟,但这只在开始时完成一次,因此对于大文件,您可能不会意识到这种开销:
@echo off
setlocal EnableExtensions DisableDelayedExpansion
rem // Define constants here:
set "_FILE=.\numbers.txt"
set /A "_DIG=10"
rem // Define global variables here:
set "$CHARS="
rem // Capture current code page and set Windows default one:
for /F "tokens=2 delims=:" %%P in ('chcp') do set /A "CP=%%P"
> nul chcp 437
rem /* Generate list of escaped characters other than numerals (escaped means every character
rem is preceded by `^`); there are some characters excluded:
rem - NUL (this cannot be stored in an environment variable and should not occur anyway),
rem - CR + LF, (they build up line-breaks, so they cannot occur within a line obviously),
rem - SPACE, (because this must be placed as the last character of the `delims`option),
rem - `"`, (because this impairs the quotation within the following code portion),
rem - `!` + `^` (they may lead to unexpected results when delayed expansion is enabled): */
setlocal EnableDelayedExpansion
for /L %%I in (0x01,1,0xFF) do (
rem // Exclude codes of aforementioned characters:
if %%I GEQ 0x30 if %%I LSS 0x3A (set "SKIP=#") else (set "SKIP=")
if not defined SKIP if %%I NEQ 0x00 if %%I NEQ 0x0A if %%I NEQ 0x0D (
if %%I NEQ 0x20 if %%I NEQ 0x21 if %%I NEQ 0x22 if %%I NEQ 0x5E (
rem // Convert code to character and append to list separated by `^`:
cmd /C exit %%I
for /F delims^=^ eol^= %%J in ('
forfiles /P "%~dp0." /M "%~nx0" /C "cmd /C echo 0x220x!=ExitCode:~-2!0x22"
') do (
set "$CHARS=!$CHARS!^^%%~J"
)
)
)
)
endlocal & set "$CHARS=%$CHARS%"
rem /* Apply escaped list of characters as delimiters and apply some of the characters
rem excluded before, namely SPACE, `"`, `!` and `^`;
rem read file using `type` in order to convert from Unicode, if applicable: */
for /F tokens^=1*^ eol^=^ ^ delims^=^!^"^^%$CHARS%^ %%K in ('type "%_FILE%"') do (
set "NUM=%%K#" & set "REST=%%L"
rem // Test whether extracted numeric string holds the given number of digits:
setlocal EnableDelayedExpansion
if "!NUM:~%_DIG%!"=="#" echo(%%K
endlocal
rem /* Current line holds more than a single numeric portion, so process them in a
rem sub-routine; this is not called if the line contains a single number only: */
if defined REST call :SUB REST
)
rem // Restore previous code page:
> nul chcp %CP%
endlocal
exit /B
:SUB ref_string
setlocal DisableDelayedExpansion
setlocal EnableDelayedExpansion
set "STR=!%~1!"
rem // Parse line string using the same approach as in the main routine:
:LOOP
if defined STR (
for /F tokens^=1*^ eol^=^ ^ delims^=^^^!^"^^^^%$CHARS%^ %%E in ("!STR!") do (
endlocal
set "NUM=%%E#" & set "STR=%%F"
setlocal EnableDelayedExpansion
rem // Test whether extracted numeric string holds the given number of digits:
if "!NUM:~%_DIG%!"=="#" echo(%%E
)
rem // Loop back if there are still more numeric parts encountered:
goto :LOOP
)
endlocal
endlocal
exit /B
此方法检测文件中所有位置的 10 位数字,即使一行中有多个数字也是如此。
关于windows - 搜索 10 个连续的个位数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44134518/
我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0
我试图获取一个长度在1到10之间的字符串,并输出将字符串分解为大小为1、2或3的连续子字符串的所有可能方式。例如:输入:123456将整数分割成单个字符,然后继续查找组合。该代码将返回以下所有数组。[1,2,3,4,5,6][12,3,4,5,6][1,23,4,5,6][1,2,34,5,6][1,2,3,45,6][1,2,3,4,56][12,34,5,6][12,3,45,6][12,3,4,56][1,23,45,6][1,2,34,56][1,23,4,56][12,34,56][123,4,5,6][1,234,5,6][1,2,345,6][1,2,3,456][123
我使用Nokogiri(Rubygem)css搜索寻找某些在我的html里面。看起来Nokogiri的css搜索不喜欢正则表达式。我想切换到Nokogiri的xpath搜索,因为这似乎支持搜索字符串中的正则表达式。如何在xpath搜索中实现下面提到的(伪)css搜索?require'rubygems'require'nokogiri'value=Nokogiri::HTML.parse(ABBlaCD3"HTML_END#my_blockisgivenmy_bl="1"#my_eqcorrespondstothisregexmy_eq="\/[0-9]+\/"#FIXMEThefoll
这似乎非常适得其反,因为太多的gem会在window上破裂。我一直在处理很多mysql和ruby-mysqlgem问题(gem本身发生段错误,一个名为UnixSocket的类显然在Windows机器上不能正常工作,等等)。我只是在浪费时间吗?我应该转向不同的脚本语言吗? 最佳答案 我在Windows上使用Ruby的经验很少,但是当我开始使用Ruby时,我是在Windows上,我的总体印象是它不是Windows原生系统。因此,在主要使用Windows多年之后,开始使用Ruby促使我切换回原来的系统Unix,这次是Linux。Rub
之前在培训新生的时候,windows环境下配置opencv环境一直教的都是网上主流的vsstudio配置属性表,但是这个似乎对新生来说难度略高(虽然个人觉得完全是他们自己的问题),加之暑假之后对cmake实在是爱不释手,且这样配置确实十分简单(其实都不需要配置),故斗胆妄言vscode下配置CV之法。其实极为简单,图比较多所以很长。如果你看此文还配不好,你应该思考一下是不是自己的问题。闲话少说,直接开始。0.CMkae简介有的人到大二了都不知道cmake是什么,我不说是谁。CMake是一个开源免费并且跨平台的构建工具,可以用简单的语句来描述所有平台的编译过程。它能够根据当前所在平台输出对应的m
深度学习部署:Windows安装pycocotools报错解决方法1.pycocotools库的简介2.pycocotools安装的坑3.解决办法更多Ai资讯:公主号AiCharm本系列是作者在跑一些深度学习实例时,遇到的各种各样的问题及解决办法,希望能够帮助到大家。ERROR:Commanderroredoutwithexitstatus1:'D:\Anaconda3\python.exe'-u-c'importsys,setuptools,tokenize;sys.argv[0]='"'"'C:\\Users\\46653\\AppData\\Local\\Temp\\pip-instal
寻找有用的ruby的好网站是什么? 最佳答案 AgileWebDevelopment列出插件(虽然不是rubygems,我不确定为什么),并允许人们对它们进行评级。RubyToolbox按类别列出gem并比较它们的受欢迎程度。Rubygems有一个搜索框。StackOverflow对最有用的rails插件和rubygems有疑问。 关于ruby-如何搜索有用的ruby,我们在StackOverflow上找到一个类似的问题: https://stacko
我有很多这样的文档:foo_1foo_2foo_3bar_1foo_4...我想通过获取foo_[X]的所有实例并将它们中的每一个替换为foo_[X+1]来转换它们。在这个例子中:foo_2foo_3foo_4bar_1foo_5...我可以用gsub和一个block来做到这一点吗?如果不是,最干净的方法是什么?我真的在寻找一个优雅的解决方案,因为我总是可以暴力破解它,但我觉得有一些正则表达式技巧值得学习。 最佳答案 我(完全)不懂Ruby,但类似这样的东西应该可以工作:"foo_1foo_2".gsub(/(foo_)(\d+)/
我读了"BingSearchAPI-QuickStart"但我不知道如何在Ruby中发出这个http请求(Weary)如何在Ruby中翻译“Stream_context_create()”?这是什么意思?"BingSearchAPI-QuickStart"我想使用RubySDK,但我发现那些已被弃用前(Rbing)https://github.com/mikedemers/rbing您知道Bing搜索API的最新包装器(仅限Web的结果)吗? 最佳答案 好吧,经过一个小时的挫折,我想出了一个办法来做到这一点。这段代码很糟糕,因为它是
我刚刚安装了带有RVM的Ruby2.2.0,并尝试使用它得到了这个:$rvmuse2.2.0--defaultUsing/Users/brandon/.rvm/gems/ruby-2.2.0dyld:Librarynotloaded:/usr/local/lib/libgmp.10.dylibReferencedfrom:/Users/brandon/.rvm/rubies/ruby-2.2.0/bin/rubyReason:Incompatiblelibraryversion:rubyrequiresversion13.0.0orlater,butlibgmp.10.dylibpro