中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-12 23:16
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS批处理 & 脚本技术(批处理室) » [Closed] sed cannot delete trailing spaces
Printable Version  2,706 / 15
Floor1 qzwqzw Posted 2008-12-16 17:37
银牌会员 Posts 636 Credits 2,343
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 ]
Floor2 HAT Posted 2008-12-16 17:57
版主 Posts 5,017 Credits 9,023
Try sed.exe 4.1.4
Batch processing room attachment collection special posthttp://www.cn-dos.net/forum/viewthread.php?tid=25914
Floor3 qzwqzw Posted 2008-12-16 18:06
银牌会员 Posts 636 Credits 2,343
Thank you very much
But what I need is win32 version of sed
Floor4 qzwqzw Posted 2008-12-16 18:23
银牌会员 Posts 636 Credits 2,343
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
Floor5 ily2013 Posted 2008-12-16 19:49
中级用户 Posts 83 Credits 247
echo \n\n\n|sed "s/\\n\\n\\n/;\\n\\n\\n/g"
Floor6 HAT Posted 2008-12-16 20:32
版主 Posts 5,017 Credits 9,023
The `-e` switch is generally used to connect multiple replacement conditions.
I wonder if the escape in floor 5 has solved your problem?
Floor7 qzwqzw Posted 2008-12-17 08:29
银牌会员 Posts 636 Credits 2,343
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.
Floor8 qzwqzw Posted 2008-12-17 08:34
银牌会员 Posts 636 Credits 2,343
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.
Floor9 ily2013 Posted 2008-12-17 09:35
中级用户 Posts 83 Credits 247
Sorry, I don't quite understand what purpose you want to achieve!
Floor10 qzwqzw Posted 2008-12-17 10:16
银牌会员 Posts 636 Credits 2,343
It's very simple. I want to replace two consecutive blank lines with ; followed by two blank lines.
Floor11 HAT Posted 2008-12-17 10:49
版主 Posts 5,017 Credits 9,023
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.
Floor12 qzwqzw Posted 2008-12-17 12:00
银牌会员 Posts 636 Credits 2,343
Semicolons need to be added at the end of the line immediately before the blank line
Floor13 qzwqzw Posted 2008-12-17 15:35
银牌会员 Posts 636 Credits 2,343
I wonder if there is a tool similar to Change under the win32 console. It's much simpler than sed.
Floor14 qzwqzw Posted 2008-12-18 09:20
银牌会员 Posts 636 Credits 2,343
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
Floor15 arkcao Posted 2010-01-26 08:55
新手上路 Posts 5 Credits 5
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?
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023