从多行字符串grep单行 [英] grep single line from multiline string
本文介绍了从多行字符串grep单行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
变量 str
包含多行字符串。我想从它那里弄出一条线。我想grep字符串行 kernel release 721
并将它分配给一个变量。有没有办法做到这一点?
A variable str
holds a multi line string. I want to grep a line from it. I want to grep the string line kernel release 721
and assign it to a variable. Is there any way to do so?
irb(main):152:0> print str
*************************** Component ********************
c:\temp\agent\bin\CAR.exe: 721, patch 618, changelist 1633822, NTAMD64, opt
**********************************************************
--------------------
AGENT information
--------------------
kernel release 721
kernel make variant 721_REL
compiled on NT 6.1 7601 S x86 MS VC++ 14.00 for NTAMD64
compiled for 64 BIT
compilation mode Non-Unicode
compile time Mar 21 2016 21:07:50
patch number 12
latest change number 1659167
---------------------
supported environment
---------------------
operating system
Windows NT 5.0
Windows NT 5.1
Windows NT 5.2
Windows NT 6.0
Windows NT 6.1
推荐答案
string.lines.grep /pattern/
或
or
string.each_line.grep /pattern/
这可能更有效率
这篇关于从多行字符串grep单行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文