Board logo

标题: [文件操作] 请问怎么通过BAT截取这个文件的指定内容? [打印本页]

作者: helpless    时间: 2021-1-4 00:42     标题: 请问怎么通过BAT截取这个文件的指定内容?

请问怎么通过BAT截取这个html文件的 mmqdedxu hkm4y,里面的字符为变量,user=8位字符的用户名mmqdedxu psw=5位字符的密码hkm4y

意思是截取了mmqdedxu和hkm4y后给予USER和PSW变量





<html><head></head><body>
</body></html>

        <textarea rows='50' cols='160' name='text'>
------------------------------------------------------------

随机用户名是mmqdedxu
随机密码是hkm4y

------------------------------------------------------------
作者: Batcher    时间: 2021-1-4 09:02

回复 1# helpless
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. for /f "delims=" %%i in ('findstr /r "随机用户名是 随机密码是" 1.html') do (
  4.     set "str=%%i"
  5.     if "!str:随机用户名是=!" neq "%%i" (
  6.         set "user=!str:随机用户名是=!"
  7.     ) else if "!str:随机密码是=!" neq "%%i" (
  8.         set "psw=!str:随机密码是=!"
  9.     )
  10. )
  11. echo,!user!
  12. echo,!psw!
  13. pause
复制代码
请参考Q-04和Q-05把bat文件和html文件都保存为ANSI编码:
https://mp.weixin.qq.com/s/6lbb97qUOs1sTyKJfN0ZEQ
作者: helpless    时间: 2021-1-4 18:09

感谢大神,问题解决了




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2