■前言
按照如下写法,可以实现替换字符串的功能
■具体操作
sed 's/hello/hi/' 321.html
替换对象 hello
替换后,显示的内容 hi
只是在输出的时候,被替换,不会改变原有的文件的内
--
■应用:
虽然,只是临时改变(不会改变原有文件中的内容),
但是,在shell脚本中,是我们可以把改变后的值,作为变量保存起来,在后续处理中使用
■区别:
s/ / /:匹配第一个
s/ / /g:匹配所有
sxz001@sxzap01:~/temp$ echo hello hello world | sed 's/hello/hi/'
hi hello world
sxz001@sxzap01:~/temp$ echo hello hello world | sed 's/hello/hi/g'
hi hi world
sxz001@sxzap01:~/temp$
■更多操作
https://blog.csdn.net/qq_37931597/article/details/86505723
■帮助文档
man sed
---
SED(1) User Commands SED(1)
NAME
sed - stream editor for filtering and transforming text
SYNOPSIS
sed [OPTION]... {script-only-if-no-other-script} [input-file]...
DESCRIPTION
Sed is a stream editor. A stream editor is used to perform basic text
transformations on an input stream (a file or input from a pipeline).
While in some ways similar to an editor which permits scripted edits
(such as ed), sed works by making only one pass over the input(s), and
is consequently more efficient. But it is sed's ability to filter text
in a pipeline which particularly distinguishes it from other types of
editors.
-n, --quiet, --silent
suppress automatic printing of pattern space
-e script, --expression=script