如何在sed正则表达式中使用\digit
我读过sed信息。在“3.3正则表达式语法概述”中。如何在sed正则表达式中使用\digit,sed,Sed,我读过sed信息。在“3.3正则表达式语法概述”中。 有一个描述: \digit Matches the digit-th \(...\) parenthesized subexpression in the regular expression. This is called a back reference. Subexpressions are implicitly numbered by counting occurrences of \( left-to-rig
有一个描述:
\digit
Matches the digit-th \(...\) parenthesized subexpression in the regular expression.
This is called a back reference. Subexpressions are implicitly numbered by
counting occurrences of \( left-to-right.
我不知道这是什么意思。谁能给我举个例子?当然
$ echo "23 45" | sed -r 's/^([0-9]*)/---\1---/'
---23--- 45
以图形方式:
sed -r 's/^([0-9]*)/---\1---/'
# ^^^^^^^^ ^^
# capture -----|
# print back
如您所见,在表单s/search/replace
上的sed表达式中,您可以在搜索块中“捕获”一个模式,然后使用\1
,\2
。。。数字是连续的,对应于第1、第2、。。。已捕获的组
$ echo "23 45" | sed -r 's/^([0-9]*) (.)/YEAH \2---\1---/'
YEAH 4---23---5
当然
以图形方式:
sed -r 's/^([0-9]*)/---\1---/'
# ^^^^^^^^ ^^
# capture -----|
# print back
如您所见,在表单s/search/replace
上的sed表达式中,您可以在搜索块中“捕获”一个模式,然后使用\1
,\2
。。。数字是连续的,对应于第1、第2、。。。已捕获的组
$ echo "23 45" | sed -r 's/^([0-9]*) (.)/YEAH \2---\1---/'
YEAH 4---23---5
另见:另见: