本文介绍了如何grep出可以改变的子字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
基本上我有一个非常大的文本文件,每一行都包含
Basically I have a very large text file and each line contains
tag=yyyyy;id=xxxxx;db_ref=zzzzz;
我想要的是 grep 出 id,但是 id 的长度和形式可以改变,我想知道是否可以使用 grep -o 然后 grep for "id=" 然后提取它之后的所有内容,直到分号?
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?
推荐答案
你可以这样做:
$ grep -o 'id=[^;]*' file
如果您不想包含 id=
部分,您可以使用正 后视:
And if you don't want to inlcude the id=
part you can using positive look-behind:
$ grep -Po '(?<=id=)[^;]*' file
这篇关于如何grep出可以改变的子字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!