求大神:用批处理bat 提取a.txt中两个指定字符串之间的内容然后生成到到新的b.txt中
a.txt文本内容一下:<divdata_goodsid="52576697020"class><divdata_goodsid="2034484207"class><d...
a.txt文本内容一下:
<div data_goodsid="52576697020" class>
<div data_goodsid="2034484207" class>
<div data_goodsid="57082150174" class>
<div data_goodsid="57715830589" class>
<div data_goodsid="54707687776" class>
<div data_goodsid="56725312624" class>
<div data_goodsid="58040866167" class>
<div data_goodsid="56688386400" class>
<div data_goodsid="3987516216" class>
<div data_goodsid="1850678761" class>
<div data_goodsid="57466971289" class>
<div data_goodsid="56868629415" class>
需要提取字符串:goodsid= 和class之间的内容,并且写入新文本b.txt中,这个是网站源代码中截取部分内容,需要使用字符串做甄别,请教如何用bat快捷实现 展开
<div data_goodsid="52576697020" class>
<div data_goodsid="2034484207" class>
<div data_goodsid="57082150174" class>
<div data_goodsid="57715830589" class>
<div data_goodsid="54707687776" class>
<div data_goodsid="56725312624" class>
<div data_goodsid="58040866167" class>
<div data_goodsid="56688386400" class>
<div data_goodsid="3987516216" class>
<div data_goodsid="1850678761" class>
<div data_goodsid="57466971289" class>
<div data_goodsid="56868629415" class>
需要提取字符串:goodsid= 和class之间的内容,并且写入新文本b.txt中,这个是网站源代码中截取部分内容,需要使用字符串做甄别,请教如何用bat快捷实现 展开
1个回答
展开全部
测试环境:WIN10,保存为bat.
第9行设置文件路径,输出结果为 "原文件名.log".
<# :
@echo off&cd/d "%~dp0"
more +8 "%~f0" >"%temp%\%~n0.ps1"
powershell -NoLogo -NoProfile -ExecutionPolicy bypass -File "%temp%\%~n0.ps1"
del /f /q "%temp%\%~n0.ps1"
pause
#>
$file='a.txt';#文件路径
$content=type $file -ReadCount 0
[system.collections.arraylist] $result=@();
foreach($line in $content)
{
if($line -match '.*<div data_goodsid="(.*)" class>.*'){[void] $result.Add($Matches[1]);}
}
set-content "$($file).log" $result;#输出结果
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |