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-25 21:27
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Closed] sed cannot delete trailing spaces View 2,563 Replies 15
Original Poster Posted 2008-12-16 17:37 ·  中国 山西 电信
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
Using win32's gun sed 3.02

Using the following statement
sed "s/ *$//" data.txt
Fails to remove trailing spaces

But using the following statement
sed "s/^ *//" data.txt
Removing leading spaces is effective

---------------------------------------------------

Removing trailing spaces works with a higher version of GNU SED (such as v4.0.7 under win32)

As for replacing three blank lines with semicolon + three blank lines, it was finally achieved with strw, the link is as follows
http://www.cn-dos.net/forum/viewthread.php?tid=39834&fpage=1&highlight=str

[ Last edited by qzwqzw on 2008-12-18 at 09:18 ]
Floor 2 Posted 2008-12-16 17:57 ·  美国 惠普HP
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Try sed.exe 4.1.4
Batch processing room attachment collection special posthttp://www.cn-dos.net/forum/viewthread.php?tid=25914
Floor 3 Posted 2008-12-16 18:06 ·  中国 山西 电信
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
Thank you very much
But what I need is win32 version of sed
Floor 4 Posted 2008-12-16 18:23 ·  中国 山西 电信
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
Found the GNU sed 4.0.7 under win32
Solved the problem of trailing spaces
But encountered a new problem
Want to replace \n\n\n with ;\n\n\n
Use
sed -e "s/\n\n\n/;\n\n\n/g" data.txt
Not working
Floor 5 Posted 2008-12-16 19:49 ·  中国 湖北 武汉 电信
中级用户
★★
Credits 247
Posts 83
Joined 2005-09-12 12:06
20-year member
UID 42446
Gender Male
Status Offline
echo \n\n\n|sed "s/\\n\\n\\n/;\\n\\n\\n/g"
Floor 6 Posted 2008-12-16 20:32 ·  中国 重庆 九龙坡区 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
The `-e` switch is generally used to connect multiple replacement conditions.
I wonder if the escape in floor 5 has solved your problem?
Floor 7 Posted 2008-12-17 08:29 ·  中国 山西 电信
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
It's not like that. I'm exactly in need of the carriage return escape, and I don't want to treat it as an ordinary text character.
Floor 8 Posted 2008-12-17 08:34 ·  中国 山西 电信
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
Strangely enough, using sed -e "s/\\n/\n/g" data.txt can replace the \n text in the text with a carriage return. That is to say, the \n such escape characters cannot be recognized in the text to be searched.
Floor 9 Posted 2008-12-17 09:35 ·  中国 湖北 武汉 电信
中级用户
★★
Credits 247
Posts 83
Joined 2005-09-12 12:06
20-year member
UID 42446
Gender Male
Status Offline
Sorry, I don't quite understand what purpose you want to achieve!
Floor 10 Posted 2008-12-17 10:16 ·  中国 山西 电信
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
It's very simple. I want to replace two consecutive blank lines with ; followed by two blank lines.
Floor 11 Posted 2008-12-17 10:49 ·  美国 惠普HP
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
I don't know if this is the meaning:
Microsoft Windows XP
(C) Copyright 1985-2001 Microsoft Corp.

C:\Test>type a.txt
aaa


bbb


ccc

C:\Test>sed "/^$/{:a;N;s/^\n$/;\n\n/;ta}" a.txt
aaa
;


bbb
;


ccc

C:\Test>sed --version
GNU sed version 4.1.4 (DJGPP port 2005-04-01 (r2))
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 12 Posted 2008-12-17 12:00 ·  中国 山西 电信
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
Semicolons need to be added at the end of the line immediately before the blank line
Floor 13 Posted 2008-12-17 15:35 ·  中国 山西 电信
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
I wonder if there is a tool similar to Change under the win32 console. It's much simpler than sed.
Floor 14 Posted 2008-12-18 09:20 ·  中国 山西 电信
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
Replace three empty lines with semicolon + three empty lines. Finally, implement it with strw. The link is as follows

http://www.cn-dos.net/forum/viewthread.php?tid=39834&fpage=1&highlight=str
Floor 15 Posted 2010-01-26 08:55 ·  中国 陕西 榆林 电信
新手上路
Credits 5
Posts 5
Joined 2010-01-24 16:36
16-year member
UID 159369
Gender Male
Status Offline
Use sed to delete trailing spaces. The output format is non-DOS format. When opened in Notepad, it doesn't wrap lines. When opened in UE, it prompts to convert to DOS mode. How to handle it?
Forum Jump: