正在寻找从下面一行中删除[11:55:43] [Server thread/INFO]:
的方法:
[11:55:43] [Server thread/INFO]: Justin has just earned the achievement [Time to Mine!]
尝试通过使用sed尝试这样做但没有运气,因为Justin可以根据获得成就的人更改为其他用户名。
有没有办法可以在用户名称之前删除[11:55:43] [Server thread/INFO]:
而无需指定它? IE浏览器。 sed from has,但保持在前面并删除任何事情?
答案 0 :(得分:1)
使用sed:
sed 's/\[.*\] \[.*\]: //' file
Justin has just earned the achievement [Time to Mine!]
答案 1 :(得分:1)
实现这一目的的sed
命令是:
sed 's/^.*: //'
e.g。
echo '[11:55:43] [Server thread/INFO]: Justin has just earned the achievement [Time to Mine!]' |\
sed 's/^.*: //'
Justin has just earned the achievement [Time to Mine!]
答案 2 :(得分:0)
使用sed
:
sed -e 's/^\[[^]]*\][^[]*\[[^]]*\]: //'
如果匹配[
(某事)]
(某事)[
(某事)]:
答案 3 :(得分:0)
这应该可以解决问题:
sed 's/.*: \([^ ]* has .*\)/\1/' file
答案 4 :(得分:0)
sed 's/^\( *\[[^]]*]\)\{2\}: //' YourFile
[...]
]:
内容中没有[...]
posix compliance(所以--posix
与GNU sed)
答案 5 :(得分:0)
A gawk
。
源文件:
$ cat infile
[11:55:43] [Server thread/INFO]: Justin has just earned the achievement [Time to Mine!]
[11:58:43] [Server thread/INFO]: Martin has just earned the achievement [Time to Mine!]
代码:
$ gawk -F']: ' 'BEGIN{OFS=""}{$1=""}1' infile
Justin has just earned the achievement [Time to Mine!]
Martin has just earned the achievement [Time to Mine!]