【问题标题】:how to grep multiple matches one line?如何grep多个匹配一行?
【发布时间】:2018-05-14 07:37:36
【问题描述】:

例如: - (id)initWithFrame:(CGRect)frame ; - (NSUInteger)hideAllHUDsForView:(UIView *)view animated:(BOOL)animated ; - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context ;

我想获取参数 eg:frame view animated keyPath...,) 和空格之间的参数,shell 上的 grep 怎么办?

【问题讨论】:

  • 有很多)s。你怎么知道你想找到哪一个?模式是什么?
  • grep -E "frame|animated|view|keyPath" someFile 也许?
  • 这就是我想问的。我写了这个egrep -o ').* ' filename,但它与整行匹配。
  • @Mark Setchell ,不是固定的,像三行这样的行要多得多。

标签: linux shell sed grep


【解决方案1】:

不完全清楚你的规则是什么,但是这个怎么样?

sed 's/[^ ]*://g;s/([^()]*)//g;s/;$//' filename

粗略的翻译,就是“去掉任何以冒号结尾的东西,然后是括号(以及它们里面的东西),然后是尾随的分号”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-15
    • 2017-05-30
    • 2011-06-10
    • 2015-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多