如何刷出可以改变的子字符串? [英] How to grep out substring which can change?
本文介绍了如何刷出可以改变的子字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
tag = yyyyy; id = xxxxx; db_ref = zzzzz ;
我想要的是刷出id,但id可以在长度和形式上改变,I想知道是否有可能使用grep -o然后grep为id =,然后提取它后面的所有内容直到分号?
解决方案
您可以这样做:
$ grep -o'id = [^;] *'文件
如果您不想包含 id =
部分你可以使用积极的后视:
$ grep -Po'(?< = id =)[^;] *'file
Basically I have a very large text file and each line contains
tag=yyyyy;id=xxxxx;db_ref=zzzzz;
What I want is to grep out the id, but the id can change in length and form, I was wondering if its possible to use grep -o and then grep for "id=" then extract everything that comes after it until the semicolon?
解决方案
You could do:
$ grep -o 'id=[^;]*' file
And if you don't want to inlcude the id=
part you can using positive look-behind:
$ grep -Po '(?<=id=)[^;]*' file
这篇关于如何刷出可以改变的子字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文