我的日志文件很大,我想从该文件中获取某些信息。我正在尝试使用grep和regex提取数据,但是我什么也没得到。
单行的格式为:
000.00.000.00,000,xxx,xxx.xxx.xxx,xxx
零=数字,x =字符
但是我想要第二个“,”之后和最后一个“,”之前的所有内容
我已经试了
grep [[a-zA-Z].\.[a-zA-Z].\.[a-zA-Z]]
和各种各样的,但我没有设法得到它
我希望得到:
','xxx.xxx.xxx','
但没有,
。
使用Perl:
perl -ape 's/^.+?[a-z]+,([^,]+).*$/$1/i' file
输出:
xxx.xxx.xxx
说明:
s/ # substitute
^ # beginning of line
.+? # 1 or more any character but newline, not greedy
[a-z]+ # 1 or more letters
, # a comma
([^,]+) # group 1, 1 or more non comma
.* # 0 or more any character but newline
$ # end of line
/ # replace with
$1 # content of group 1
/i # case insensitive
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句