我正在尝试删除文本文件中行尾的句点.有些行在结尾处有句号,有些则没有:
$cat textfile
sometexthere.123..22.no_period
moretext_with_period. **<-- remove this period**
no_period_here_either
period. **<-- remove this period**
Run Code Online (Sandbox Code Playgroud)
我试过这个,但它似乎不起作用:
sed 's/\.$//g' textfile > textfile2
Run Code Online (Sandbox Code Playgroud)
(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 ~]$
Run Code Online (Sandbox Code Playgroud)
这个例子 -
[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.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15316 次 |
| 最近记录: |