本文介绍了sed - 删除行尾的句点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试删除文本文件中位于行尾的句点.有些行的末尾有句点,有些则没有:
I'm trying to remove periods that are at the end of line in a text file. Some lines have periods at the end, some don't:
$cat textfile
sometexthere.123..22.no_period
moretext_with_period. **<-- remove this period**
no_period_here_either
period. **<-- remove this period**
我已经试过了,但它似乎不起作用:
I've tried this, but it doesn't seem to work:
sed 's/\.$//g' textfile > textfile2
(GNU sed 版本 4.2.1)
(GNU sed version 4.2.1)
谢谢
推荐答案
这是摸不着头脑的,但我之前尝试将 Windows 文件与 Linux 文件混合时遇到了这个问题.Windows 在每个换行符处添加一个额外的 \r
(除了标准的 \n
)您是否尝试过使用 dos2unix?
This is a shot in the dark, but I had this problem before when I tried to mix Windows files with Linux files. Windows adds an extra \r
on every line break (in addition to the standard \n
)Have you tried using dos2unix?
[user@localhost ~]$ cat testfile
abc
def.
[user@localhost ~]$ sed 's/\.$//g' testfile
abc
def.
[user@localhost ~]$ dos2unix testfile
dos2unix: converting file testfile to UNIX format ...
[user@localhost ~]$ sed 's/\.$//g' testfile
abc
def
[user@localhost ~]$
例如这个 -
[user@localhost ~]$ cat temp.txt
this is a text created on windows
I will send this to unix
and do cat command.
[user@localhost ~]$ cat -v temp.txt
this is a text created on windows^M
I will send this to unix^M
and do cat command.
这篇关于sed - 删除行尾的句点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!