Note of sed

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Note of sed相关的知识,希望对你有一定的参考价值。

refers to <Linux Command Line and Shell Scripting Bible>

date:Sep 17 2016

 

format for using sed command:

           set options script file

 


 

command of ‘s‘,the s command substitutes a second text string for the first text string pattern specified between the forward slashes.

技术分享

(The sed command executes and returns the data almost instantaneously. As it processes each line of data,the results are displayed,You‘ll start seeing results before the sed editor completes processing the entire file.)

技术分享


To execute more than one command from the sed command line, just use the -e option:

技术分享

and I notice this: the second command will edit the text base on the first command‘s result.

技术分享


 

If you have lots of commands you want to process, it is often easier to just store them in a separate file.Use -f option to specify the file in the sed command:

技术分享    

(tip:It can be easy to confuse your sed editor script files with your bash shell script files. To eliminate confusion, use a .sed file extension on your sed script files.)


 The substitute command works fine in replacing text in multiple lines, but by default,it replaces only the first occurrence in each line.

技术分享

So you must use a substitution flag.

Four types of substitution flags are available:

         A number,indicating the pattern occurrence for which new text should be subsittuted.

技术分享

        g, indicating that new text should be substituted for all occurrences of existing text.

技术分享

        p,indicating that the contents of the original line should be printed.

技术分享

        w file,which means to write the results of the subsititution to a file.

技术分享


 

以上是关于Note of sed的主要内容,如果未能解决你的问题,请参考以下文章

Note of Python Math

My Study Note of JDBC

note of camel in action--chapter 1

My Study Note of JDBC (2.1)

Note of Jieba ( 词云图实例 )

Beginning Scala study note Basics of Scala