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的主要内容,如果未能解决你的问题,请参考以下文章