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-08-09 03:50
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Use sed to delete blank lines made up of spaces View 1,885 Replies 18
Original Poster Posted 2008-07-13 12:30 ·  中国 辽宁 营口 中移铁通
中级用户
★★
Credits 206
Posts 93
Joined 2007-08-16 17:19
18-year member
UID 95263
Gender Male
Status Offline
Use sed to delete blank lines made up of spaces
Floor 2 Posted 2008-07-13 12:37 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
致精致简!
Floor 3 Posted 2008-07-13 12:52 ·  中国 辽宁 营口 中移铁通
中级用户
★★
Credits 206
Posts 93
Joined 2007-08-16 17:19
18-year member
UID 95263
Gender Male
Status Offline
Seems like it doesn't do anything
Floor 4 Posted 2008-07-13 13:13 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Originally posted by amio at 2008-7-13 12:52:
Seems like it doesn't do anything

What do you mean by “seems like”?
Did you test it?
Why does it test fine for me。。。
致精致简!
Floor 5 Posted 2008-07-13 13:18 ·  中国 辽宁 营口 中移铁通
中级用户
★★
Credits 206
Posts 93
Joined 2007-08-16 17:19
18-year member
UID 95263
Gender Male
Status Offline
sed -i "/^ *$/d" a.txt|find /v ""

This is how I tested it
Floor 6 Posted 2008-07-13 14:01 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
If you wanted to modify the source file directly, then you should have made that clear in the first post.。
Nope.
致精致简!
Floor 7 Posted 2008-07-13 14:38 ·  中国 重庆 九龙坡区 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Floor 8 Posted 2008-07-13 16:31 ·  中国 辽宁 营口 中移铁通
中级用户
★★
Credits 206
Posts 93
Joined 2007-08-16 17:19
18-year member
UID 95263
Gender Male
Status Offline
Originally posted by HAT at 2008-7-13 02:38 PM:
@echo off
sed "/^ *$/d" a.txt>b.txt
move /y b.txt a.txt



Did you test whether this works? Why doesn't mine work then?
Floor 9 Posted 2008-07-13 16:44 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
The OP is really something, just one sentence saying it doesn't work.
What exactly is the problem, and where doesn't it work? Are you really that stingy? Can't even bear to describe what happens when it doesn't work?
People are trying to help you, don't act like they're the ones begging you。。。
致精致简!
Floor 10 Posted 2008-07-13 17:04 ·  中国 重庆 九龙坡区 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
I tested it, and it works.
Maybe your sed version is too old.

C:\Test>C:\ProgramMy\GnuWin32\sed --version
GNU sed version 4.1.5
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
to the extent permitted by law.
Floor 11 Posted 2008-07-13 17:21 ·  中国 辽宁 营口 中移铁通
中级用户
★★
Credits 206
Posts 93
Joined 2007-08-16 17:19
18-year member
UID 95263
Gender Male
Status Offline
Sorry, I got it wrong. What I meant was deleting the spaces at the beginning of a line. Delete only the leading spaces, but keep the text after them.

For example:
aaaaaaaaaaa
becomes
aaaaaaaaaaa
Floor 12 Posted 2008-07-13 17:29 ·  中国 重庆 九龙坡区 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
@echo off
sed "s/^ *//g" a.txt>b.txt
move /y b.txt a.txt

Next time when asking a question, it's best to give an example right in the first post, hehe.
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
amio +2 2008-07-13 17:33
Floor 13 Posted 2008-07-13 17:35 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Could it really be a sed version issue? Doesn't HAT's sed need find for filtering?
:

@echo off
sed "s/^ *//g" a.txt|find /v "">b.txt
move /y b.txt a.txt
致精致简!
Floor 14 Posted 2008-07-13 17:38 ·  中国 辽宁 营口 中移铁通
中级用户
★★
Credits 206
Posts 93
Joined 2007-08-16 17:19
18-year member
UID 95263
Gender Male
Status Offline
This was given on the CU forum. Does it mean the same thing?
sed 's/^[[:blank:]]\+//'
Floor 15 Posted 2008-07-13 18:56 ·  中国 重庆 九龙坡区 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
If you've lurked on CU long enough, then you'd know that [[:blank:]] includes not only spaces, but all blank characters, hehe.
Forum Jump: