我正在尝试删除文本文件中行尾的句点。有些行的末尾有句点,有些则没有:
$cat textfile
sometexthere.123..22.no_period
moretext_with_period. **<-- remove this period**
no_period_here_either
period. **<-- remove this period**
我试过这个,但它似乎不起作用:
sed 's/\.$//g' textfile > textfile2
(GNU sed 版本 4.2.1)
谢谢
最佳答案
这是黑暗中的一个镜头,但我之前在尝试将 Windows 文件与 Linux 文件混合时遇到了这个问题。 Windows 添加了一个额外的 \r
在每个换行符上(除了标准 \n
)您是否尝试过使用 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.
关于regex - sed - 删除行尾的句点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8317447/