Board logo

标题: [文本处理] 批处理如何提取文本中的IP+端口号到一个新的文本? [打印本页]

作者: wuyuanwuyu    时间: 2023-12-18 16:56     标题: 批处理如何提取文本中的IP+端口号到一个新的文本?

有一个从网上抓取并生成的a.txt文本,里面的内容如下:{"result":{"id":"04cc2d078993232ddhffsdjkjr8a","targets":[{"target":"url","constraint":{"operator":"matches","value":"www.test.com\/*"}}],"actions":[{"id":"forwarding_url","value":{"url":"http:\/\/114.224.114.224:1011\/$1","status_code":301}}],"priority":1,"status":"active","created_on":"2023-11-30T04:06:26.000000Z","modified_on":"2023-12-17T23:00:43.000000Z"},"success":true,"errors":[],"messages":[]}

文本中的IP114.224.114.224和端口号1011是变动的,如何用批处理将“IP:端口号”提取并写入一个新的txt文本?谢谢大佬
作者: ShowCode    时间: 2023-12-18 17:46

回复 1# wuyuanwuyu
  1. @echo off
  2. set "OldFile=a.txt"
  3. set "NewFile=b.txt"
  4. cd /d "%~dp0"
  5. for /f "tokens=13,14 delims=:" %%a in ('type "%OldFile%"') do (
  6.     for /f "tokens=3 delims=/" %%i in ("%%a") do (
  7.         set "MyIP=%%i"
  8.     )
  9.     for /f "tokens=1 delims=\" %%i in ("%%b") do (
  10.         set "MyPort=%%i"
  11.     )
  12. )
  13. echo>"%NewFile%" %MyIP%:%MyPort%
复制代码





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