本文介绍了如何使用grep来提取子字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的命令:

lockquote
grep -E'\ * [[:它的输出结果如下:[]:+ FIN [[:space:]] +([^)] +?)')myfile


$ b

我只想输出:

如何告诉 grep 来做到这一点?


 <$> 

c $ c> grep -E'* [[:space:]] + FIN [[:space:]] +([^)] +?)')myfile | awk'{print $ 2}'

我不确定如何单独使用grep来做到这一点,因为它并不是真正适合这种确切的用例。因为你在一个grep平台上,所以当你有一个命令解决问题的一部分时,使用管道是你的优势,另一个命令则是另一个命令。


Here is my command :

It outputs :

And I would like it outputs only :

How can I tell grep to do it ?

解决方案

You can pipe the output of your grep command to the awk command.

grep -E '*[[:space:]]+FIN[[:space:]]+([^)]+?)') myfile | awk '{print $2}'

I am not sure how to do that with grep alone, as it is not really tailored to that exact use case. Since you are on a platform where grep is, use pipes to your advantage when you can have one command solve part of the problem, and another command the other part.

这篇关于如何使用grep来提取子字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 13:09
查看更多