简体   繁体   English

sed 单行

[英]Sed only one-liner

I need to use sed to parse out some text.我需要使用sed来解析一些文本。 I can't use cut because of some syntax it causes with Ansible in this particular case.我不能使用 cut ,因为在这种特殊情况下它会导致 Ansible 的某些语法。 I was hoping to achieve this just with sed.我希望仅使用 sed 就可以实现这一目标。 This is a single line of text.这是单行文本。

    "_ref": "record:host/ZG5zLmhvc3QkLl9kZWZhdWx0Lm5ldC5kdHZvcHMuYW5keXRlc3QwMg:pootest02.catt.net/Internal"

I need to print out everything after the third "(quote) and before the third :(colon).我需要在第三个 "(quote) 之后和第三个 :(colon) 之前打印出所有内容。

My expected outcome should be:我的预期结果应该是:

    record:host/ZG5zLmhvc3QkLl9kZWZhdWx0Lm5ldC5kdHZvcHMuYW5keXRlc3QwMg

Any help or direction is greatly appreciated.非常感谢任何帮助或指导。

Try this :尝试这个 :

sed -r 's/^".*".*"(.*):.*/\1/'

but if it's a JSON like chepner said in comments, really try 但如果它是像chepner在评论中所说的JSON,真的试试

这就是最终工作得很好的原因:

sed -n -e 's#.*\\(record:[^:]\\+\\):.*#\\1#p'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM