我有一个程序将创建一个带有如下输出的文本文件:
...
AF
Aug 05 16:27:01.310 [notice] Tor 0.3.5.8 running on Linux with Libevent 2.1.8-stable, OpenSSL 1.1.1c, Zlib 1.2.11, Liblzma 5.2.4, and Libzstd 1.3.8.
Aug 05 16:27:01.310 [notice] Tor can't help you if you use it wrong! Learn how to be safe at https://www.torproject.org/download/download#warning
Aug 05 16:27:01.311 [notice] Read configuration file "/etc/tor/torrc".
Aug 05 16:27:01.314 [notice] Opening Socks listener on 127.0.0.1:9050
Aug 05 16:27:01.314 [notice] Opened Socks listener on 127.0.0.1:9050
Aug 05 16:27:01.000 [notice] Parsing GEOIP IPv4 file /usr/share/tor/geoip.
Aug 05 16:27:01.000 [notice] Parsing GEOIP IPv6 file /usr/share/tor/geoip6.
Aug 05 16:27:01.000 [notice] Bootstrapped 0%: Starting
Aug 05 16:27:01.000 [notice] Starting with guard context "default"
Aug 05 16:27:11.000 [notice] Catching signal TERM, exiting cleanly.
AX
Aug 05 16:27:11.333 [notice] Tor 0.3.5.8 running on Linux with Libevent 2.1.8-stable, OpenSSL 1.1.1c, Zlib 1.2.11, Liblzma 5.2.4, and Libzstd 1.3.8.
Aug 05 16:27:11.333 [notice] Tor can't help you if you use it wrong! Learn how to be safe at https://www.torproject.org/download/download#warning
Aug 05 16:27:11.333 [notice] Read configuration file "/etc/tor/torrc".
Aug 05 16:27:11.338 [notice] Opening Socks listener on 127.0.0.1:9050
Aug 05 16:27:11.338 [notice] Opened Socks listener on 127.0.0.1:9050
Aug 05 16:27:11.000 [notice] Parsing GEOIP IPv4 file /usr/share/tor/geoip.
Aug 05 16:27:11.000 [notice] Parsing GEOIP IPv6 file /usr/share/tor/geoip6.
Aug 05 16:27:11.000 [notice] Bootstrapped 0%: Starting
Aug 05 16:27:12.000 [notice] Starting with guard context "default"
Aug 05 16:27:21.000 [notice] Catching signal TERM, exiting cleanly.
...
本质上,它将检查 TOR 是否可以通过不同的国家/地区进行连接。我做到了,所以它在段落之前输出 ISO alpha-2 代码,然后是一个空的返回行。
如何创建一个可以解析每个单独段落的程序,搜索文本“100%”,如果存在,将 alpha-2 代码(段落上方)复制到不同的文件中,使用 bash '>>'
如果您的输入包含由一个或多个空行分隔的记录,那么您可以在段落模式下使用 awk 或 perl
或者