Board logo

标题: [文本处理] 这种数据批处理无法提取吧 [打印本页]

作者: woshi110`    时间: 2023-8-3 09:54     标题: 这种数据批处理无法提取吧

本帖最后由 woshi110` 于 2023-8-3 10:20 编辑

我最终目前是要提取SSID=""和PreSharedKey="" 这个数据,但是我想把带SAE的network={}这整个数据去掉,这个SSID重复了,这种是不是不好实现啊
network={
ConfigKey="209"WPA_PSK
SSID="209"
PreSharedKey="00000000"
WEPTxKeyIndex=0
HiddenSSID=false
AllowedKeyMgmt=02
AllowedProtocols=03
AllowedAuthAlgos=
AllowedGroupCiphers=0f
AllowedPairwiseCiphers=06
CreatorUid=1000
MacRandomizationSetting=3
}
network={
ConfigKey="209"SAE
SSID="209"
PreSharedKey="00000000"
WEPTxKeyIndex=0
HiddenSSID=false
AllowedKeyMgmt=0001
AllowedProtocols=02
AllowedAuthAlgos=
AllowedGroupCiphers=a8
AllowedPairwiseCiphers=2c
CreatorUid=1000
MacRandomizationSetting=3
}
network={
ConfigKey="217"WPA_PSK
SSID="217"
PreSharedKey="00000000"
WEPTxKeyIndex=0
HiddenSSID=false
AllowedKeyMgmt=02
AllowedProtocols=03
AllowedAuthAlgos=
AllowedGroupCiphers=0f
AllowedPairwiseCiphers=06
CreatorUid=1000
MacRandomizationSetting=3
}
network={
ConfigKey="217"SAE
SSID="217"
PreSharedKey="00000000"
WEPTxKeyIndex=0
HiddenSSID=false
AllowedKeyMgmt=0001
AllowedProtocols=02
AllowedAuthAlgos=
AllowedGroupCiphers=a8
AllowedPairwiseCiphers=2c
CreatorUid=1000
MacRandomizationSetting=3
}


最终效果:
SSID="110110"
PreSharedKey="Huawei12#$"
SSID="209"
PreSharedKey="00000000"
作者: qixiaobin0715    时间: 2023-8-3 10:13

楼主最好将示范文本传到网盘上,方便大家测试用。
作者: pd1    时间: 2023-8-3 10:17

你就把上面这一段处理完是什么样的给出来吧
作者: woshi110`    时间: 2023-8-3 10:20

回复 3# pd1


    SSID="110110"
PreSharedKey="Huawei12#$"
SSID="209"
PreSharedKey="00000000"
作者: Batcher    时间: 2023-8-3 10:41

回复 4# woshi110`


    你给的文本内容里面没有SSID="110110"这个字符串,结果里面的从哪来的呢?
作者: pd1    时间: 2023-8-3 10:55

  1. <# :
  2. @echo off
  3. powershell -NoProfile -ExecutionPolicy bypass "Get-Content -literal '%~f0' |Out-String|Invoke-Expression"
  4. pause
  5. #>
  6. $a='''network={
  7. ConfigKey="209"WPA_PSK
  8. SSID="209"
  9. PreSharedKey="00000000"
  10. WEPTxKeyIndex=0
  11. HiddenSSID=false
  12. AllowedKeyMgmt=02
  13. AllowedProtocols=03
  14. AllowedAuthAlgos=
  15. AllowedGroupCiphers=0f
  16. AllowedPairwiseCiphers=06
  17. CreatorUid=1000
  18. MacRandomizationSetting=3
  19. }
  20. network={
  21. ConfigKey="209"SAE
  22. SSID="209"
  23. PreSharedKey="00000000"
  24. WEPTxKeyIndex=0
  25. HiddenSSID=false
  26. AllowedKeyMgmt=0001
  27. AllowedProtocols=02
  28. AllowedAuthAlgos=
  29. AllowedGroupCiphers=a8
  30. AllowedPairwiseCiphers=2c
  31. CreatorUid=1000
  32. MacRandomizationSetting=3
  33. }
  34. network={
  35. ConfigKey="217"WPA_PSK
  36. SSID="217"
  37. PreSharedKey="00000000"
  38. WEPTxKeyIndex=0
  39. HiddenSSID=false
  40. AllowedKeyMgmt=02
  41. AllowedProtocols=03
  42. AllowedAuthAlgos=
  43. AllowedGroupCiphers=0f
  44. AllowedPairwiseCiphers=06
  45. CreatorUid=1000
  46. MacRandomizationSetting=3
  47. }
  48. network={
  49. ConfigKey="217"SAE
  50. SSID="217"
  51. PreSharedKey="00000000"
  52. WEPTxKeyIndex=0
  53. HiddenSSID=false
  54. AllowedKeyMgmt=0001
  55. AllowedProtocols=02
  56. AllowedAuthAlgos=
  57. AllowedGroupCiphers=a8
  58. AllowedPairwiseCiphers=2c
  59. CreatorUid=1000
  60. MacRandomizationSetting=3
  61. }
  62. '''
  63. $regex = [regex]'SSID=".*?"[\s\S]+?PreSharedKey=".*?"'
  64. $regex.Matches($a)|Select-Object -Unique|select Value|%{$_.Value}
复制代码

作者: aloha20200628    时间: 2023-8-3 11:52


近来有数帖均属此类题型,因数据格式简单规整,样本量也很小,用纯P代码解之效率尚可》先锚定标志行,再从其后连续行获取目标数据...
假设样本数据存于 src.ini 与本脚本同目录,编码采用ansi/简中编码
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. set "got="
  4. (for /f "delims=" %%s in (src.ini) do (
  5. set "sc=%%s"
  6. if /i "!sc:~,10!"=="ConfigKey=" (if /i "!sc:~-3!" neq "SAE" (set "got=1")) else if defined got (
  7. if !got! geq 1 (echo,%%s)
  8. if !got! equ 2 (set "got=") else (set/a got+=1)
  9. )
  10. ))>new.ini
  11. endlocal &exit/b
复制代码

作者: woshi110`    时间: 2023-8-3 14:26

回复 6# pd1


    ok,可以的感谢 !
作者: xczxczxcz    时间: 2023-8-3 15:00

回复 6# pd1


    回溯好多++
作者: hfxiang    时间: 2023-8-3 15:39

回复 1# woshi110`
使用第3方工具gawk( http://bcn.bathome.net/tool/5.1.0/gawk.exe )比较简单:
  1. gawk -v"FS=\n" -v"RS=}\n" "$2!~/^ConfigKey.+SAE$/{print $3 FS $4}" a.txt>b.txt
复制代码

作者: pd1    时间: 2023-8-3 17:31

回复 9# xczxczxcz


    我就是看的网上的那些教程,回溯这些原理确实没搞明白




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