Board logo

标题: [文本处理] bat脚本怎么提取 a,b文本行 格式 以 逗号, 分割 a=b 的文本行? [打印本页]

作者: idc878787    时间: 2022-3-24 10:36     标题: bat脚本怎么提取 a,b文本行 格式 以 逗号, 分割 a=b 的文本行?

bat提取 a,b文本行 格式  以 逗号, 分割 a=b 的文本行???怎么写?

例如:文本1.txt

https://www.baidu.com/s?wd=site:[url]www.qq.com/[/url],https://www.baidu.com/s?wd=site:[url]www.qq.com/[/url]
https://www.baidu.com/s?wd=site:[url]www.qq.com/[/url],https://www.baidu.com/s?wd=site:[url]www.qq.com/accessibility/[/url]
https://www.baidu.com/s?wd=site:[url]www.qq.com/[/url],https://www.baidu.com/s?wd=site:[url]www.qq.com/history/[/url]
https://www.baidu.com/s?wd=site:[url]www.qq.com/[/url],https://www.baidu.com/s?wd=site:[url]www.qq.com/map/[/url]
https://www.baidu.com/s?wd=site:[url]www.qq.com/[/url],https://www.baidu.com/s?wd=site:[url]www.qq.com/sheweishou...htm[/url]
https://www.baidu.com/s?wd=site:[url]www.qq.com/[/url],https://www.baidu.com/s?wd=site:[url]www.qq.com/xiaos...htm[/url]
https://www.baidu.com/s?wd=site:[url]www.qq.com/[/url],https://www.baidu.com/s?wd=site:[url]www.qq.com/contra...shtml[/url]
https://www.baidu.com/s?wd=site:[url]www.qq.com/[/url],https://www.baidu.com/s?wd=site:[url]www.qq.com/wa/[/url]
https://www.baidu.com/s?wd=site:[url]www.qq.com/[/url],https://www.baidu.com/s?wd=site:[url]www.qq.com/?fromdefa...[/url]
https://www.baidu.com/s?wd=site:[url]www.sxxinju.com/[/url],https://www.baidu.com/s?wd=site:[url]www.sxxinju.com/[/url]
https://www.baidu.com/s?wd=site:[url]www.sxxinju.com/[/url],https://www.baidu.com/s?wd=site:[url]www.sxxinju.com/sheweishou...htm[/url]

提取 以 逗号, 分割 a=b 的文本行    生成文本2.txt

https://www.baidu.com/s?wd=site:[url]www.qq.com/[/url],https://www.baidu.com/s?wd=site:[url]www.qq.com/[/url]
https://www.baidu.com/s?wd=site:[url]www.sxxinju.com/[/url],https://www.baidu.com/s?wd=site:[url]www.sxxinju.com/[/url]
作者: qixiaobin0715    时间: 2022-3-24 11:10

  1. @echo off
  2. (for /f "tokens=1* delims=," %%i in (1.txt) do if "%%i"=="%%j" echo,%%i,%%j)>2.txt
复制代码

作者: idc878787    时间: 2022-3-24 11:19

回复 2# qixiaobin0715


       3Q  3Q
作者: Batcher    时间: 2022-3-24 11:44

回复 1# idc878787


如果文本行数较多,可以试试命令行工具 gawk.exe 效率如何:
http://bcn.bathome.net/s/tool/index.html?key=gawk
  1. gawk "BEGIN{FS=OFS=\",\"}{if($1==$2)print}" 1.txt > 2.txt
复制代码





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