Board logo

标题: [文本处理] 批处理怎样提取关键字的行和行里面的字符串? [打印本页]

作者: senkiss    时间: 2024-2-2 17:37     标题: 批处理怎样提取关键字的行和行里面的字符串?

config nodes 'ELmqb2VQ'
  option address '167.88.182.251'
config nodes 'ua7p4EM8'
   option address '45.159.51.106'

怎么提取出这种格式 'ELmqb2VQ' '167.88.182.251'
作者: hfxiang    时间: 2024-2-2 19:17

回复 1# senkiss

用第3方工具gawk( http://bcn.bathome.net/tool/4.1.0/gawk.exe )的实现方式如下:
  1. gawk "/config nodes/,/option address/{if(/config nodes/){a=$NF};if(/option address/){print a,$NF}}" 1.txt>2.txt
复制代码

作者: newswan    时间: 2024-2-2 20:45

不需要前面的
  1. /config nodes/,/option address/
复制代码

作者: ppll2030    时间: 2024-2-2 21:18

代码保存为bat文件。把源文件拖拽进去即可得到结果。
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. set file=%~1
  4. for /f "tokens=1-3 delims= " %%i in ('findstr /ic:"config nodes" /ic:"option address" "%file%"') do (
  5.    if "%%i %%j" == "config nodes" set a=%%k
  6.    if "%%i %%j" == "option address" set a=!a! %%k&&echo !a!
  7. )
  8. pause
复制代码

作者: senkiss    时间: 2024-2-2 21:38

回复 4# ppll2030

好像啥也不显示!
其实我的本来的文件是这样字的

config nodes '6M0yhiK7'
        option tls '1'
        option protocol 'vless'
        option tcp_guise 'none'
        option tlsflow 'xtls-rprx-vision'
        option port '26338'
        option re
        option add_mode '1'
        option type 'Xray'
        option timeout '60'
        option reality '1'
        option tls_allowInsecure '0'
        option tls_serverName 'www.amazon.com'
        option uuid
        option reality
        option address '45.159.50.156'
        option encryption 'none'
        option fingerprint 'ios'
        option add_from '导入'
        option transport 'tcp'

config nodes '3iZQevS1'
        option tls '1'
        option protocol 'vless'
        option tcp_guise 'none'
        option tlsflow 'xtls-rprx-vision'
        option port '647
        option add_mode '1'
        option type 'Xray'
        option timeout '60'
        option reality '1'
        option tls_allowInsecure '0'
        option tls_serverName 'www.cloudflare.com'
        option uuid
        option reality_pub
        option address '45.159.51.94'
        option encryption 'none'
        option fingerprint 'ios'
        option add_from '导入'
        option transport 'tcp'

config nodes 'U1NNbFG7'
        option tls '1'
        option protocol 'vless'
        option tcp_guise 'none'
        option tlsflow 'xtls-rprx-vision'
        option port '48792'
        option remarks
        option add_mode '1'
        option type 'Xray'
        option timeout '60'
        option reality '1'
        option tls_allowInsecure '0'
        option tls_serverName 'www.paypal.com'
        option uuid
        option reality_pub
        option address '167.88.182.73'
        option encryption 'none'
        option fingerprint 'ios'
        option add_from '导入'
        option transport 'tcp'

后面还有格式一样的我需要的是提取config nodes 后面'U1NNbFG7' 和optionaddress 后面  '167.88.182.73'然后输出成 'U1NNbFG7' '167.88.182.73'
作者: senkiss    时间: 2024-2-2 21:41

回复 2# hfxiang


感谢这样子可以!
作者: senkiss    时间: 2024-2-2 21:41

回复  senkiss

用第3方工具gawk(  )的实现方式如下:
hfxiang 发表于 2024-2-2 19:17


这样子就是我想要的
作者: ppll2030    时间: 2024-2-2 23:15

回复 5# senkiss
直接把源文件拖到bat文件上就可以了,不用先运行bat的。
作者: Batcher    时间: 2024-2-3 19:31

回复 5# senkiss


    请把原始文件上传到网盘,下载地址更新在顶楼,我试试。




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