Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这样的一行:
14:32:38,723 [一些文字] 错误 - 更多文字......
我想删除直到(但不包括)第一个“[”的所有内容(这样结果就是以 [some text] ..... 开头的行)
我的阅读
's/^.*\d*\s//'
是它应该将所有内容替换为一个数字后跟一个空格,但它似乎在行中的任何地方都应用替换,即贪婪。
我试过了:
's/^.*\s\[//g'
但它正在剥离第一个“[”
如何修改任一表达式以执行我需要的操作?非常感谢
我会应用以下 sed 命令
s/^[^[]*\[/\[/
它用[单个[.
[
$ echo "14:32:38,723 [some text] ERROR - some more" | sed 's/^[^[]*\[/\[/' [some text] ERROR - some more text
这可能对您有用:
sed 's/[^[]*//' file