这是什么sed命令的意思吗? SED的%^ * / %%' [英] What's the meaning of this sed command? sed 's%^.*/%%'
问题描述
我看到了一个bash命令 SED的%^ * / %%'
I saw a bash command sed 's%^.*/%%'
通常对于sed的常用语法为 SED的/模式/ STR / G'
,但在这其中它使用 S%^。 *
在的/模式/ STR / G'的
。 取值
部分
Usually the common syntax for sed is sed 's/pattern/str/g'
, but in this one it used s%^.*
for the s
part in the 's/pattern/str/g'
.
我的问题:结果
这是什么 S%^ *
意思?结果
什么是 %%
在的第二部分SED意义的%^ * / %%'
?
My questions:
What does s%^.*
mean?
What's meaning of %%
in the second part of sed 's%^.*/%%'
?
推荐答案
的%
是一个另类的分隔符,这样你就不必逃避包含在正斜杠匹配的部分。
The %
is an alternative delimiter so that you don't need to escape the forward slash contained in the matching portion.
所以,如果你写相同的前pression与 /
作为分隔符,它看起来像:
So if you were to write the same expression with /
as a delimiter, it would look like:
sed 's/^.*\///'
这是一种难以阅读也。
which is also kind of difficult to read.
无论哪种方式,前pression将查找在线路正斜杠;如果有一个斜杠,除去一切直至并包括了斜杠。
Either way, the expression will look for a forward slash in a line; if there is a forward slash, remove everything up to and including that slash.
这篇关于这是什么sed命令的意思吗? SED的%^ * / %%'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!