
标题: [文本处理] [已解决]批处理字符串截取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
- for /f "tokens=1,2 delims=:" %%a in (ipgroup.txt) do (echo %%a %%b)
复制代码
作者: yhcfsr 时间: 2018-1-25 02:48
POWERSHELL- $SourceFile="D:\test mu\ipgr oup.txt"
- $OutFile="D:\test mu\output.txt"
- $result=Get-Content -path $SourceFile|%{$_ -split "outerip`":`""}|%{$_ -split "`",`""}|?{$_ -match "(\d+\.){3}\d+"}|Out-File -FilePath $OutFile
- 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 编辑
- @echo off
- Setlocal enabledelayedexpansion
- for /f "delims=" %%i in (ipgroup.txt) do (
- set "str=%%i"
- for %%j in ([ { } ]) do (
- set str=!str:%%j=!
- )
-
- for %%a in (!str!) do (
- set "_%%a=%%a"
- )
- )
-
- for /f "tokens=1,* delims==" %%i in ('set _^|findstr "outerip"') do (
- set "str=%%j"&set str=!str:":"=","!
- for %%a in (!str!) do set "str=%%~a"
- echo,!str!
- )
- pause
复制代码
作者: 523066680 时间: 2018-2-5 19:12
凑个热闹- use Modern::Perl;
- use JSON;
- use File::Slurp;
-
- my $text = read_file( "ipgroup.txt" );
- my $struct = from_json( $text );
-
- for my $e ( @$struct )
- {
- for my $ips ( @{ $e->{ips} } )
- {
- say $ips->{name}, " - ", $ips->{outerip};
- }
- }
复制代码
作者: 老刘 时间: 2018-2-7 13:31
凑热闹+1,存批- ' &cscript -e:vbscript -nologo "%~0" >结果.txt &start "" 结果.txt
- Text = CreateObject("Scripting.FileSystemObject"). _
- GetFile("ipgroup.txt"). _
- OpenAsTextStream(1). _
- ReadAll
- Set regex = New RegExp
- regex.Global = True
- regex.Pattern="\d+\.\d+\.\d+\.\d+:\d+"
- For Each match In regex.Execute(text)
- wsh.echo match
- Next
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |