linux中g s在文件中的使用方法,Linux中的sed命令,使用方法之一「替换字符串中的内容 」,以及「s/ / / 」和「s/ / /g」之间的区别...

■前言

按照如下写法,可以实现替换字符串的功能

■具体操作

sed 's/hello/hi/' 321.html

替换对象 hello

替换后,显示的内容 hi

只是在输出的时候,被替换,不会改变原有的文件的内

--

1ce93e430d14f1bd1437e9f2aff982c2.png

■应用:

虽然,只是临时改变(不会改变原有文件中的内容),

但是,在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$

adf969a7a44058a5b3ce025ca0553397.png

■更多操作

https://blog.csdn.net/qq_37931597/article/details/86505723

■帮助文档

man sed

c6e0caef84a2d11b81e8fb67a7cbe2a8.png

---

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值