使用 sed 打印分隔符之间的文本
假设我有 op(abc)asdfasdf
并且需要 sed
在括号之间打印 abc
。什么对我有用? (注意:我只想要一行中第一对分隔符之间的文本,如果特定的输入行没有一对括号,则不需要任何文本。)
Suppose I have op(abc)asdfasdf
and I need sed
to print abc
between the brackets. What would work for me? (Note: I only want the text between first pair of delimiters on a line, and nothing if a particular line of input does not have a pair of brackets.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该模式查找以零个或多个不是左括号的字符列表开头的行,然后查找以左括号开头的行;然后开始记住零个或多个不是右括号的字符的列表,然后是右括号,后面是任何内容。将输入替换为您记住的列表并打印它。
-n
表示“默认不打印”——任何不带括号的输入行都不会被打印。The pattern looks for lines that start with a list of zero or more characters that are not open parentheses, then an open parenthesis; then start remembering a list of zero or more characters that are not close parentheses, then a close parenthesis, followed by anything. Replace the input with the list you remembered and print it. The
-n
means 'do not print by default' - any lines of input without the parentheses will not be printed.