在特定字词和/之后逐个删除字词 [英] Sed out word after specific word and /

查看:64
本文介绍了在特定字词和/之后逐个删除字词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用grep在文本文件中搜索/Users/.这是输出:

I am using grep to search out /Users/ in a text file. This is the output:

'dir': u'/Users/dlee/Desktop',

有没有办法将Users/之后的单词读出来?也就是说,要获取dlee作为输出?

Is there a way to sed out the word after Users/? That is, to get dlee as the output?

推荐答案

使用grep和Perl正则表达式:

With grep and Perl regex:

$ grep -Po '(?<=/Users/)[^/]*' <<< "'dir': u'/Users/dlee/Desktop',"
dlee

  • -o仅返回匹配项
  • (?<=/Users/)是正向后看",即比赛必须在比赛之后,但不包括在内
  • [^/]*是除正斜杠之外的任意数量的字符
    • -o returns only the match
    • (?<=/Users/) is a "positive look-behind", i.e., the match has to be preceded by it but it is not included
    • [^/]* is any number of characters except forward slashes
    • 这篇关于在特定字词和/之后逐个删除字词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆