简体   繁体   English

Unix Shell脚本-Sed命令

[英]Unix shell scripting - Sed command

I'm new to unix shell scripting and I wanted to learn how exactly the below command works: 我是unix shell脚本的新手,我想了解以下命令的工作原理:

sed "s/~[0-9]*$//" sample_file

I know that sed does an input transformation on a file which is the sample_file that I mentioned above. 我知道sed对文件进行输入转换,该文件就是我上面提到的sample_file。 I wanted to know what exactly s/~[0-9]*$// does. 我想知道s/~[0-9]*$//到底s/~[0-9]*$//做什么s/~[0-9]*$//

Help is appreciated. 感谢帮助。

this regexp removes tilde ~ and numbers that follow the tilde from the given string, if nothing else follows the numbers. 此正则表达式从给定的字符串中删除波浪号~以及波浪号后面的数字,如果数字后面没有其他内容。

given command will only remove characters in its output. 给定的命令只会删除其输出中的字符。 if you need to change file contents, you'll have to add -i like: 如果需要更改文件内容,则必须添加-i例如:

sed "s/~[0-9]*$//" -i sample_file

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM