[英]Sed regex in bash issues
Can someone tell me why this sed below doesn't work有人能告诉我为什么下面的这个 sed 不起作用吗
...| sed -E $'s/^\d/blah/g'
vs this one works? vs 这个有用吗?
| sed -E $'s/^/blah/g'
sample:样本:
echo "10/30/18 04:45:13 PM EDT" | sed -E $'s/^/blah/'
Updated desire:更新的愿望:
echo "10/30/18 04:45:13 PM EDT" |
sed 's/^[[:digit:]][[:digit:]]\/[[:digit:]][[:digit:]]\/[[:digit:]][[:digit:]]/\blah\n/'
blah
10/30/18 04:45:13 PM EDT
Property \\d
(digits) works in PCRE/Perl but not in BRE or ERE flavors that is used by sed
.属性\\d
(数字)适用于 PCRE/Perl,但不适用于sed
使用的 BRE 或 ERE 风格。
Use [[:digit:]]
instead of \\d
in sed
:在sed
使用[[:digit:]]
而不是\\d
:
sed 's/^[[:digit:]]/blah/'
For your updated question use this gnu sed
command:对于您更新的问题,请使用此gnu sed
命令:
echo "10/30/18 04:45:13 PM EDT" |
sed -E 's~^([[:digit:]]{2}/){2}[[:digit:]]{2}~\blah\n&~'
blah
10/30/18 04:45:13 PM EDT
This might work for you (GNU sed):这可能对你有用(GNU sed):
sed '/^..\/..\/.. ..:..:.. /iblah' file
Inserts blah
above the regexp and:在正则表达式上方插入blah
并:
sed '/^..\/..\/.. ..:..:.. /ablah' file
Appends blah
below the regexp.在正则表达式下方附加blah
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.