|
qzwqzw
银牌会员
     天的白色影子
积分 2343
发帖 636
注册 2004-3-6
状态 离线
|
『楼 主』:
[已结]sed无法删除行尾空格
使用 LLM 解释/回答一下
使用win32下的gun sed 3.02
使用以下语句
sed "s/ *$//" data.txt
删除行尾空格无效
但使用以下语句
sed "s/^ *//" data.txt
删除行首空格是有效的
---------------------------------------------------
删除行尾空格使用更高版本的GNU SED(比如win32下v4.0.7)就可以了
至于替换三个空行为分号+三个空行的问题最后用strw实现,链接如下
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 ]
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 ]
|
|
2008-12-16 17:37 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
|
2008-12-16 17:57 |
|
|
qzwqzw
银牌会员
     天的白色影子
积分 2343
发帖 636
注册 2004-3-6
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
非常感谢
不过我需要的是win32下的sed
Thank you very much
But what I need is win32 version of sed
|
|
2008-12-16 18:06 |
|
|
qzwqzw
银牌会员
     天的白色影子
积分 2343
发帖 636
注册 2004-3-6
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
找到了win32下的gnu sed 4.0.7
解决了行尾空格问题
却遇到了新问题
想把\n\n\n替换为;\n\n\n
使用
sed -e "s/\n\n\n/;\n\n\n/g" data.txt
无效
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
|
|
2008-12-16 18:23 |
|
|
ily2013
中级用户
  
积分 247
发帖 83
注册 2005-9-12
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
echo \n\n\n|sed "s/\\n\\n\\n/;\\n\\n\\n/g"
echo \n\n\n|sed "s/\\n\\n\\n/;\\n\\n\\n/g"
|
|
2008-12-16 19:49 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 6 楼』:
Re 4楼
使用 LLM 解释/回答一下
-e开关一般用来连接多个替换条件吧
不知道5楼的转义是否解答你了的问题?
The `-e` switch is generally used to connect multiple replacement conditions.
I wonder if the escape in floor 5 has solved your problem?
|

 |
|
2008-12-16 20:32 |
|
|
qzwqzw
银牌会员
     天的白色影子
积分 2343
发帖 636
注册 2004-3-6
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
不是这样的
我正需要\n的回车转义
而不想把它作为普通文本字符
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.
|
|
2008-12-17 08:29 |
|
|
qzwqzw
银牌会员
     天的白色影子
积分 2343
发帖 636
注册 2004-3-6
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
奇怪的是
使用 sed -e "s/\\n/\n/g" data.txt
却可以把文本中的\n文本替换为回车
也就是说在要查找的文本里
无法识别\n这样的转义字符
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.
|
|
2008-12-17 08:34 |
|
|
ily2013
中级用户
  
积分 247
发帖 83
注册 2005-9-12
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
sorry,不太明白你想实现什么目的!
Sorry, I don't quite understand what purpose you want to achieve!
|
|
2008-12-17 09:35 |
|
|
qzwqzw
银牌会员
     天的白色影子
积分 2343
发帖 636
注册 2004-3-6
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
很简单
我想实现将 连续两个空行 替换 为;后加两个空行
It's very simple. I want to replace two consecutive blank lines with ; followed by two blank lines.
|
|
2008-12-17 10:16 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 11 楼』:
Re 10楼
使用 LLM 解释/回答一下
不知道是不是这个意思:
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.
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.
|

 |
|
2008-12-17 10:49 |
|
|
qzwqzw
银牌会员
     天的白色影子
积分 2343
发帖 636
注册 2004-3-6
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
分号需加在空行前一行的行尾
Semicolons need to be added at the end of the line immediately before the blank line
|
|
2008-12-17 12:00 |
|
|
qzwqzw
银牌会员
     天的白色影子
积分 2343
发帖 636
注册 2004-3-6
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
不知是否存在win32 console下的类似Change的工具
比sed要简单很多了
I wonder if there is a tool similar to Change under the win32 console. It's much simpler than sed.
|
|
2008-12-17 15:35 |
|
|
qzwqzw
银牌会员
     天的白色影子
积分 2343
发帖 636
注册 2004-3-6
状态 离线
|
|
2008-12-18 09:20 |
|
|
arkcao
新手上路

积分 5
发帖 5
注册 2010-1-24
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
使用sed删除尾部空格 输出的格式为非dos格式 记事本打开显示不换行 用ue打开提示转换为dos模式 如何处理?
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?
|
|
2010-1-26 08:55 |
|