Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
For loop 批处理-如何使用html中的for/f设置变量_For Loop_Batch File_Substring - Fatal编程技术网

For loop 批处理-如何使用html中的for/f设置变量

For loop 批处理-如何使用html中的for/f设置变量,for-loop,batch-file,substring,For Loop,Batch File,Substring,在批处理中,我使用curl将html输出到一个文件(output.txt),然后将对输出文件的搜索发送到一个新文件(search.txt)。搜索结果输出约4000个字符的长行,其中包括()[]/“;:,” 从这里,我尝试使用for/f提取一个var,但失败了,因此我想在一个新文件中使用作为换行符,将长行拆分为较小的行 我试过类似的问题,但这种方法似乎对特殊角色也不起作用。对此的任何帮助都将不胜感激。谢谢 编辑:应Stephan的要求 这是一个工作示例: echo off curl -L "htt

在批处理中,我使用curl将html输出到一个文件(output.txt),然后将对输出文件的搜索发送到一个新文件(search.txt)。搜索结果输出约4000个字符的长行,其中包括()[]<>/“;:,”

从这里,我尝试使用for/f提取一个var,但失败了,因此我想在一个新文件中使用
作为换行符,将长行拆分为较小的行

我试过类似的问题,但这种方法似乎对特殊角色也不起作用。对此的任何帮助都将不胜感激。谢谢

编辑:应Stephan的要求

这是一个工作示例:

echo off
curl -L "https://cnn.com" >output.txt
findstr "bounty" "output.txt" | findstr "ad_oop_float_01" >search.txt
output.txt:

output.txt is too big for stackoverflow and pastebin
search.txt:

<div class="OUTBRAIN" data-src="" data-widget-id="TR_1" data-ob-template="cnnedition"></div><script>(function (d) {var e = d.createElement('script');e.async = true;e.type = 'text/javascript';e.onload = function _onJSMDLoad(e) {jQuery(d).triggerAnalyticsReady();};e.src = '//agility.cnn.com/turner/cnn-prod/Bootstrap.js';d.body.appendChild(e);})(document);</script><script src="/.a/2.212.2/js/cnn-footer-lib-react.min.js"></script><script async src="/.a/2.212.2/js/gigya-sharebar.min.js" type="text/plain" class="optanon-category-smv"></script><script src="//a.postrelease.com/serve/load.js?async=true"></script><script>if (WM.UserConsent.inUserConsentState(["perf-general"], {id: "usabilla"})) {CNN.INJECTOR.loadFeature('usabilla');}</script><script async src="//native.sharethrough.com/assets/sfp.js"></script><script>(function (doc, fd) {fd.measure(function () {var scpt = doc.getElementsByTagName('script')[0];fd.mutate(function () {WM.UserConsent.addScript({async: true,id: 'quantScript',src: (doc.location.protocol === 'https:' ? 'https://secure.quantserve.com/quant.js' : 'http://edge.quantserve.com/quant.js'),type: 'text/javascript'}, ["ads-vendor"], scpt.parentNode);});});}(document, fastdom));</script><noscript><img src="//pixel.quantserve.com/pixel/p-D1yc5zQgjmqr5.gif?labels=noscript%3ANo%20Labels%20Set" style="display: none;" border="0" height="1" width="1" alt="Quantcast"/></noscript><script>window._sf_async_config = window._sf_async_config || {};window._sf_async_config.uid = 37612;window._sf_async_config.domain = '' || 'edition.cnn.com';window._sf_async_config.flickerControl = false;window._sf_async_config.useCanonical = true;/* Prevent Chartbeat from automatically checking the page for videos */window._sf_async_config.autoDetect = false;var _sf_startpt=Date.now();WM.UserConsent.addScript({async: true,src: '//static.chartbeat.com/js/chartbeat_mab.js'}, ["perf-general"]);</script><script>(function(w, d, c, u) {var f, n, i;w[u] = w[u] || [],f = function () {var o = {ti: '5526986'};o.q = w[u];w[u] = new UET(o);w[u].push('pageLoad');},n = d.createElement('script'),n.async = 1,n.onload = n.onreadystatechange = function() {var s = this.readyState;s && s !== 'loaded' && s !== 'complete' || (f(), n.onload = n.onreadystatechange = null);},n.src = '//bat.bing.com/bat.js',i = d.getElementsByTagName('script')[0],c.UserConsent.addScriptElement(n, ["perf-vendor"], i.parentNode);})(window, document, WM, 'uetq');</script><script>if (!CNN.Features || CNN.Features.enableBounceX !== false) {(function (d) {WM.UserConsent.addScript({async: true,src: d.location.protocol + '//tag.bounceexchange.com/340/i.js'}, ["iab","behavior-vendor","person-vendor","storage-vendor"]);})(document);}</script><script>(function($){$(document).onZonesAndDomReady(function () {if (Modernizr.android === true) {$('head').append('<meta name="theme-color" content="#000000">');$('head').append('<link href="//cdn.cnn.com/cnn/.e/img/3.0/global/misc/cnn-logo.png" rel="icon" sizes="192x192">');}});}(jQuery));</script><script data-obct>!function(_window, _document) {var OB_ADV_ID = '00b2d6c56fc76084821b9d05abf2f201d9',api,tag,script;if (_window.obApi) {if (!Array.isArray(_window.obApi.marketerId)) {_window.obApi.marketerId = [_window.obApi.marketerId];}return;}api = _window.obApi = function () {var a = window.obApi;a.dispatch ? a.dispatch.apply(a, arguments) : a.queue.push(arguments);};api.version = '1.0';api.loaded = true;api.marketerId = OB_ADV_ID;api.queue = [];tag = _document.createElement('script');tag.async = true;tag.src = '//amplify.outbrain.com/cp/obtp.js';script = _document.getElementsByTagName('script')[0];WM.UserConsent.addScriptElement(tag, ["iab","behavior-vendor"], script.parentNode);}(window, document);obApi('track', 'PAGE_VIEW');document.addEventListener('click', function(event) {var el = event.target;if (el && (el.tagName === 'A' || (el.parentNode && el.parentNode.tagName === 'A'))) {obApi('track', 'Exit Link Clicks');}});</script><script>if (WM.UserConsent.inUserConsentState(["perf-vendor","social-vendor"], {id: "twitterPixel"})) {(function (w, d) {var e,s;if (!w.twq) {s = w.twq = function () {s.exe ? s.exe.apply(s, arguments) : s.queue.push(arguments);};s.version = '1.1';s.queue = [];e = d.createElement('script');e.async = true;e.type = 'text/javascript';e.src = '//static.ads-twitter.com/uwt.js';d.getElementsByTagName('body')[0].appendChild(e);}})(window, document);twq('init', 'nyutn');twq('track', 'PageView');}</script><script>if (console) {console.log(' ');console.log('  .d8888b.  888b    888 888b    888');console.log(' d88P  Y88b 8888b   888 8888b   888');console.log(' 888    888 88888b  888 88888b  888    We are trying to make CNN.com faster.');console.log(' 888        888Y88b 888 888Y88b 888    Think you can help?');console.log(' 888        888 Y88b888 888 Y88b888');console.log(' 888    888 888  Y88888 888  Y88888    Send your ideas to: bounty AT cnnlabs DOT com');console.log(' Y88b  d88P 888   Y8888 888   Y8888');console.log('  "Y8888P"  888    Y888 888    Y888');console.log(' ');}</script><script>(function (win, doc, WM) {win['bt'] = win['bt'] || function () { (win['_bt'] = win['_bt'] || []).push(arguments); };WM.UserConsent.addScript({async: true,src: '//cdn.boomtrain.com/p13n/cnn/p13n.min.js'}, ["person-vendor"]);})(window, document, WM);</script><div class="ad ad--epic ad--all-skin"><div id="ad_oop_skin_01" class="ad-ad_oop_skin_01 ad-refresh-adbanner"></div></div><div class="ad ad--epic ad--all"><div id="ad_oop_float_01" class="ad-ad_oop_float_01 ad-refresh-adbody"></div></div><div class="ad ad--epic ad--all"><div id="ad_oop_float_02" class="ad-ad_oop_float_02 ad-refresh-adbody"></div></div></body></html>

Batch处理这样的字符串非常糟糕。Gladly编写了一个JScript/Batch混合脚本,完全支持正则表达式,这使此任务非常简单:

for /f "delims=" %%a in ('^<test.txt jrepl.bat ".* class=\q(.*) .*" "$1" /XSEQ') do set "class=%%a"
echo class=%class%

对于/f“delims=“%%a in(“^很明显,您知道批处理文件解析器在某些字符方面的局限性,为什么不使用一种脚本语言来选择或替换子字符串呢?Compo我需要批量执行此操作,但我不完全知道这些局限性,我仍在努力解决。如果有人可以如何分割文件我非常感谢!请描述您的
for/F
尝试以何种方式失败,因为它不会由于行长度限制而失败,因为
for/F
最多可以读取8KB的行(您说的是4K字符)!什么是
output.txt
(ASCII/ANSI,Unicode)的文本编码?aschipfl
output.txt
上的编码是Unix(LF)UTF-8,但我正在互选的文件是
search.txt
Windows(CRLF)UTF-8。问题不在于行长,我从/f
中得到了奇怪的结果,我似乎找不到一个不超过26的合适分隔符,但谢谢你,我没有检查编码。我以前遇到过这个问题,必须通过管道将文本从文件返回到文件来更正它。谢谢Stephan。这是一个很好的选择,但在结束我能够找到一个唯一的分隔符,但是我仍然需要一个将字符串从分隔符拆分为子字符串的解决方案。对于一个完全不同的字符串,这是一个完全不同的任务。请参阅我对新问题的回答。
for /f "delims=" %%a in ('^<test.txt jrepl.bat ".* class=\q(.*) .*" "$1" /XSEQ') do set "class=%%a"
echo class=%class%