用于删除每行点结尾的 Bash 脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22569726/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 09:58:56 来源:igfitidea点击:
Bash script to remove dot end of each line
提问by user3347931
Unix command to remove dot at end of each line in file.
Unix 命令删除文件中每行末尾的点。
Sample rec in file
文件中的示例记录
11234567 0.
23456789 5569.
34567810 1.
10162056 0.
回答by jaypal singh
Just use sed
:
只需使用sed
:
sed 's/\.$//' yourfile
- Escape the special character
.
using\
. - Put an achor
$
to only remove it from the end. - To make infile changes use
-i
option ofsed
.
- 逃离特殊字符
.
使用\
。 - 放一个 achor
$
只将它从末端移除。 - 为了使INFILE改变使用
-i
的选项sed
。
回答by sehe
sed -e 's/\.$//'
done. (padding to make answer long enough. grumble)
完毕。(填充以使答案足够长。抱怨)
回答by keelerm
sed -i 's/\.$//' /path/to/file
This will match a literal period that is anchored to the end of the line, and replace it with nothing. The -itells sed to make the change inline.
这将匹配锚定到行尾的文字句点,并将其替换为空。该-i告诉sed进行更改在线。