Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.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
Batch file 如何提取在文本文件中移动的文本行_Batch File - Fatal编程技术网

Batch file 如何提取在文本文件中移动的文本行

Batch file 如何提取在文本文件中移动的文本行,batch-file,Batch File,我试图从一个每天都在变化的网页中删除一个链接,我已经成功地得到了一行文本,但我无法得到它,因为它周围的字符不断干扰我的尝试,我不是很擅长它,基本上一直在屠宰其他脚本来尝试解决它,现在在第12小时,我已经承认失败,需要帮助 我的重点是在文本文件中包含以下内容 </a><p>Support the free distribution of this forecast by visiting our sponsors website.<p><b>

我试图从一个每天都在变化的网页中删除一个链接,我已经成功地得到了一行文本,但我无法得到它,因为它周围的字符不断干扰我的尝试,我不是很擅长它,基本上一直在屠宰其他脚本来尝试解决它,现在在第12小时,我已经承认失败,需要帮助 我的重点是在文本文件中包含以下内容

    </a><p>Support the free distribution of this forecast by visiting our sponsors website.<p><b>Select forecast - </b><a href="?fdate=140403">Tomorrow</a> / <a href="?fdate=140404">Friday</a> / <a href="?fdate=140405">Saturday</a><p><hr><h5>Viewing forecast for Thursday, 3rd April, 2014</h5><p>Forecast last reviewed on Wednesday, 02/04/14 at 16:17<p><a href="jnzolmdtgobavkjz/EH.PDF" target="blank" border="0"><img src="images/pdf.gif" align="left"></a><br><a href="jnzolmdtgobavkjz/EH.PDF" target="blank">Click here to access the PDF version of the forecast</a>.<br><br><br><br><hr><h5>Summary for all mountain areas</h5><p>Low cloud will remain widespread across eastern mountains south to about the central or southern Pennines. Higher summits may well be above the cloud. Outbreaks of rain will move north, locally heavy. Local gusty winds.<p><hr><h5>Headline, Cairngorms National Park, Monadhliath</h5><p>Outbreaks of rain; hazy. Locally gusty wind.<p><p><hr><h5>How Windy?</h5><p>East or southeasterly, 20 to occasionally 30 or 35mph.<p><h5>Effect Of Wind?</h5><p>Will impede ease of walking on some areas, not necessarily the highest areas. Sudden gusts west of major ridges and some passes and cols.<p><hr><h5>How Wet?</h5><p>Bursts of rain<p>Rain now and again, ranging from brief light showers to heavier bursts lasting an hour or two - these most likely west of the A9.<p><hr><h5>Cloud on the hills?</h5><p>Widespread east<p>Most, perhaps all higher areas intermittently cloud free. But very low cloud over North Sea will shroud areas accessible from Deeside from lower slopes, although higher tops (above about 900m) often above the cloud.<p><h5>Chance of cloud free Munros?</h5><p>80%<p><h5>Sunshine and air clarity?</h5><p>Patchy weak sunshine. Very hazy low level, but excellent visibility many higher slopes. Extensive fog eastern mountains, particularly lower slopes.<p><hr><h5>How Cold? (at 900m)</h5><p>4 to 6C, but 2C where in cloud.<p><h5>Freezing level</h5><p>Above the summits<p><hr><h5>Planning Outlook for all mountain areas from Friday, 4th April, 2014</h5><p>Winds will turn south to southwesterly into the weekend as rain bearing fronts come in off the Atlantic. Snowmelt in Scotland will continue. Winds at times approaching or reaching gale higher areas. 
通过访问我们的赞助商网站来支持此预测的免费发布。选择预测-/
查看2014年4月3日星期四的预测上一次审查的预测是在星期三,2014年4月2日16时17分





所有山区的总结低云将继续广泛分布在东部山区,从南到大约宾夕法尼亚州中部或南部。更高的山峰可能在云层之上。暴雨将向北移动,局部地区将出现暴雨。当地阵风。
标题,凯恩戈姆斯国家公园,蒙纳迪亚斯雨的爆发;朦胧的。局部阵风。
风有多大?偏东或偏东南,20到偶尔30或35英里/小时。风的影响?会妨碍在某些区域行走,不一定是在最高区域。大山脊以西、一些山口和沼泽地突然刮起阵风。
多湿?阵雨时而下,从短暂的小阵雨到持续一到两个小时的大阵雨-这些阵雨最有可能发生在A9以西。
山丘上的云?大部分地区,也许所有较高的地区都间歇性地无云。但北海上空极低的云层将覆盖从较低斜坡从Deeside进入的区域,尽管较高的顶部(约900米以上)通常在云层上方。无云Munros的可能性?80%阳光和空气透明度?零星弱阳光。低空有雾,但能见度很好,有许多较高的斜坡。东部山区雾弥漫,尤其是较低的山坡。
有多冷?(900米处)4至6摄氏度,但云层中的温度为2摄氏度。山顶上方的冰冻层
计划从2014年4月4日(星期五)开始对所有山区进行展望由于有雨锋面进入大西洋,周末风将从南转向西南风。苏格兰的融雪将继续。有时接近或到达大风较高地区的风。
我想要的输出是:jnzolmdtgobavkjz/EH.PDF

我已经设法解决了问题的其余部分,但由于地址的长度每天都在变化,我还没有设法解决怎么做

如果它可以在bat中或从bat初始化,那将非常好,或者输出到一个文本文件,这样我就可以继续在bat中处理它

希望有人能帮忙

干杯

萨姆

试试这个:

文本文件的名称:
input.txt
输出被放入:
output.txt

@ECHO Off
setlocal enabledelayedexpansion

for /f  "delims=" %%a in ('type input.txt') do (
set ligne=%%a
set ligne=!ligne:^<p^>^<a href^== #1# !
set ligne=!ligne: target= #2# !
)

set sw1=0

for %%b in (!ligne!') do (
if "%%b"=="#2#" goto:end
if !sw1!==1 echo %%b>Output.txt
if "%%b"=="#1#" set sw1=1
)
goto:eof

:end
type output.txt
endlocal
pause
@ECHO关闭
延迟扩展
对于/f“delims=“%%a in('type input.txt')do(
设置直线=%%a

set ligne=!ligne:^^正如我在评论中所说的,您尚未指定查找目标行/字符串的规则,因此我们只能猜测……下面的批处理文件将查找同时包含“href”和“target”字符串的第一行,并提取括在引号中的第二个标记:

@echo off

for /F ^tokens^=2^delims^=^" %%a in ('findstr "href" input.txt ^| findstr "target"') do echo %%a& goto continue
:continue
输出:

jnzolmdtgobavkjz/EH.PDF

如果此方法不能解决您的问题,请指定规则…

您在问题中粘贴的单行可以通过REPL.BAT解析如下

它所做的是查找双引号前面4个字符的句点
\.
,并提供从该句点之前的双引号到匹配的双引号的文本。它返回
“jnzolmdtgobavkjz/EH.PDF”
,如果您希望它不带双引号,也可以这样做

repl:这使用名为
repl.bat的助手批处理文件-下载自:

repl.bat
放在与批处理文件相同的文件夹中,或放在路径上的文件夹中

type "file.txt"| repl ".*(\q.*\....\q).*" "$1" x >newfile.txt
@ECHO关闭
SETLOCAL ENABLEDELAYEDEXPANSION
对于/f“delims=”(q22821879.txt)中的%%a,请设置“行=%%a”
:循环
设置“行=!行:*=!”

如果不是“%line:~0,8%”=="你只是忘了解释我是如何找到这行的!这不是唯一一行带有
@Aacini的代码。代码被有效编辑了,但输入了人工破译。原始帖子在一行中包含所有内容。代码被有效编辑了,但输入了人工破译。原始帖子在一行中包含所有内容。我没有检查你的代码。我只是告诉你源代码格式已经更改,当我测试你的代码时,输出是:
?fdate=140403
@sachadee:Oops!我使用了由…
:-(