Board logo

标题: [文本处理] [已解决]批处理字符串截取IP和端口号 [打印本页]

作者: luohao8810    时间: 2018-1-24 18:09     标题: [已解决]批处理字符串截取IP和端口号

下面的文本文档里面,截取到里面的IP和端口号
例如
175.155.24.35:33890
175.155.24.20:33890
作者: ivor    时间: 2018-1-24 19:38

  1. for /f "tokens=1,2 delims=:" %%a in (ipgroup.txt) do (echo %%a %%b)
复制代码

作者: yhcfsr    时间: 2018-1-25 02:48

POWERSHELL
  1. $SourceFile="D:\test mu\ipgr oup.txt"
  2. $OutFile="D:\test mu\output.txt"   
  3. $result=Get-Content -path $SourceFile|%{$_ -split "outerip`":`""}|%{$_ -split "`",`""}|?{$_ -match "(\d+\.){3}\d+"}|Out-File -FilePath $OutFile
  4. pause
复制代码

作者: luohao8810    时间: 2018-1-25 09:08

回复 2# ivor


    您好,您这个代码运行之后获取的不是IP和端口号
作者: luohao8810    时间: 2018-1-25 10:15

回复 3# yhcfsr


    后续脚本有问题还能请教吗?
作者: yhcfsr    时间: 2018-1-25 12:57

回复 5# luohao8810


    加我QQ吧,33892006
作者: 慕夜蓝化    时间: 2018-2-5 17:16

本帖最后由 慕夜蓝化 于 2018-2-5 17:19 编辑
  1. @echo off
  2. Setlocal enabledelayedexpansion
  3. for /f "delims=" %%i in (ipgroup.txt) do (
  4. set "str=%%i"
  5. for %%j in ([ {  } ]) do (
  6. set str=!str:%%j=!
  7. )
  8. for %%a in (!str!) do (
  9. set "_%%a=%%a"
  10. )
  11. )
  12. for /f "tokens=1,* delims==" %%i in ('set _^|findstr "outerip"') do (
  13. set "str=%%j"&set str=!str:":"=","!
  14. for %%a in (!str!) do set "str=%%~a"
  15. echo,!str!
  16. )
  17. pause
复制代码

作者: 523066680    时间: 2018-2-5 19:12

凑个热闹
  1. use Modern::Perl;
  2. use JSON;
  3. use File::Slurp;
  4. my $text = read_file( "ipgroup.txt" );
  5. my $struct = from_json( $text );
  6. for my $e ( @$struct )
  7. {
  8.     for my $ips ( @{ $e->{ips} } )
  9.     {
  10.         say $ips->{name}, " - ", $ips->{outerip};
  11.     }
  12. }
复制代码

作者: 老刘    时间: 2018-2-7 13:31

凑热闹+1,存批
  1. ' &cscript -e:vbscript -nologo "%~0" >结果.txt &start "" 结果.txt
  2. Text = CreateObject("Scripting.FileSystemObject"). _
  3. GetFile("ipgroup.txt"). _
  4. OpenAsTextStream(1). _
  5. ReadAll
  6. Set regex = New RegExp
  7. regex.Global = True
  8. regex.Pattern="\d+\.\d+\.\d+\.\d+:\d+"
  9. For Each match In regex.Execute(text)
  10. wsh.echo match
  11. Next
复制代码





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