China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-22 10:13
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to delete empty lines without using sed View 2,076 Replies 18
Floor 16 Posted 2007-08-30 17:33 ·  中国 北京 朝阳区 联通
银牌会员
★★★
Credits 1,287
Posts 634
Joined 2007-05-02 15:06
19-year member
UID 87277
Gender Male
From cmd.exe
Status Offline
...........No consideration was given to this matter...It's over...........

@echo off
set runtimes=0
FOR /F "delims=" %%i in (myfile.txt) do (
call :func1 "%%i" "%%i"
)
pause
pause
pause
:func1
set /a runtimes=%runtimes%+1
set EL=1
set T1=%1
set T1=%T1: =%
if NOT %T1%=="" set EL=0
if %EL%==0 (
if NOT %runtimes%==1 echo+>>done.txt
set /p "null=%2"<nul>>done.txt
)
goto :EOF
Floor 17 Posted 2007-08-30 18:45 ·  中国 广东 广州 白云区 电信
中级用户
★★
Credits 259
Posts 112
Joined 2006-09-18 04:55
19-year member
UID 62928
Gender Male
Status Offline
Hehe..Indeed interesting..Creative..Learned!~
Floor 18 Posted 2007-08-30 18:59 ·  中国 湖北 仙桃 电信
中级用户
★★
Credits 301
Posts 135
Joined 2007-05-15 16:49
19-year member
UID 88615
Gender Male
Status Offline
Originally posted by knoppix7 at 2007-8-30 05:33 PM:
...........没有考虑这个事。。。完了。。。。。。。

@echo off
set runtimes=0
FOR /F "delims=" %%i in (myfile.txt) do (
call :func1 "%%i" "%%i"
...

The spaces in front of non-empty lines are also removed.
Floor 19 Posted 2007-12-21 12:48 ·  中国 安徽 马鞍山 电信
中级用户
★★
拟谷盗
Credits 312
Posts 108
Joined 2007-01-21 11:36
19-year member
UID 77238
Gender Male
Status Offline
It can be used like this. Note that there is a space before *, sed "/^ *$/d"

# Delete all blank lines in the file
sed '/^$/d' # Method 1
sed '/./!d' # Method 2
Forum Jump: