批处理筛选重复内容
时间: 2023-08-16 11:04:28 浏览: 50
可以使用批处理程序来筛选文本文件中的重复内容。以下是一个示例脚本:
```
@echo off
setlocal enabledelayedexpansion
set input_file=%1
set output_file=%2
if "%input_file%" == "" (
echo Usage: finddupes.bat <input_file> <output_file>
exit /b 1
)
if "%output_file%" == "" (
echo Usage: finddupes.bat <input_file> <output_file>
exit /b 1
)
if exist %output_file% del /f /q %output_file%
for /f "tokens=*" %%a in ('type "%input_file%" ^| sort') do (
if "!prev!" == "%%a" (
echo %%a >> %output_file%
)
set prev=%%a
)
exit /b 0
```
该脚本从命令行中接收两个参数:输入文件和输出文件。它首先使用 `sort` 命令对输入文件进行排序,然后逐行扫描文件内容。对于每行内容,如果它与上一行内容相同,则将其写入输出文件中。最后,输出文件中将只包含重复的行。要使用该脚本,请在命令行中输入:
```
finddupes.bat <input_file> <output_file>
```
其中 `<input_file>` 是要筛选的文本文件,`<output_file>` 是输出文件。
相关推荐
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![text/plain](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)