【发布时间】:2020-09-04 23:42:30
【问题描述】:
我正在尝试提出一个 sed 语句,该语句将匹配正则表达式以包含不以反引号 ` 开头的每一行。
目标是在不以反引号开头的每一行添加一些内容。
反引号可以在行首或前面有一个或多个空格(或制表符),我需要匹配的任何其他行,即使是有反引号的行不是一开始。
这是我目前所拥有的:
cat myfile.txt
`this line starts with backtick`
`this one does too, but there are some spaces`
!some stuff on May 14 19:52:58 2020
more stuff *(&) 243123123123
indented stuff
indented stuff
string here that is nothing special
*here is an asterisk
match `this line`
1 number one
2 number two
`ignore this one`
这是我的 sed 表达式(在 Mac 上)。
sed -e 's/^\([^[\s*`].*\)/--matched--\1/g' myfile.txt
`this line starts with backtick`
--matched-- `this one does too, but there are some spaces`
--matched--!some stuff on May 14 19:52:58 2020
--matched--more stuff *(&) 243123123123
--matched-- indented stuff
--matched-- indented stuff
string here that is nothing special
*here is an asterisk
--matched-- match `this line`
--matched-- 1 number one
--matched-- 2 number two
--matched-- `ignore this one`
编辑:清晰度
【问题讨论】:
标签: macos sed regex-negation regexp-replace