用Bat写一个去除txt长文件中的空行脚本
时间: 2024-05-26 18:11:05 浏览: 17
可以参考以下的Bat脚本:
@echo off
set input_file=%1
set output_file=%2
if "%input_file%" == "" (
echo Usage: %0 input_file output_file
exit /b 1
)
if not exist "%input_file%" (
echo %input_file% does not exist.
exit /b 1
)
if "%output_file%" == "" (
set output_file=output.txt
)
echo Removing empty lines from %input_file%...
findstr /r /v "^$" "%input_file%" > "%output_file%"
echo Done.
在命令行中执行该脚本时,需要提供两个参数:输入文件和输出文件,例如:
remove_empty_lines.bat input.txt output.txt
如果没有提供输出文件名,则默认为 output.txt。该脚本使用 findstr 命令来查找输入文件中的非空行,并将它们写入输出文件中。
相关问题
用bat写个批量去除txt文件内空行的代码
@echo off
setlocal EnableDelayedExpansion
for %%a in (*.txt) do (
set "content="
for /f "usebackq delims=" %%b in ("%%a") do (
set "line=%%b"
if defined line (
set "content=!content!%%b"
)
)
echo !content!>"%%a"
)
echo Done!
用bat写个去除txt文件内空行的代码
@echo off
setlocal EnableDelayedExpansion
set "file=input.txt"
set "outfile=output.txt"
(for /f "delims=" %%a in ('type "%file%"') do (
set "line=%%a"
if defined line (
echo !line!
)
)) > "%outfile%"
echo "Done!"
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![.rar](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)
![](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)