我有一个包含 n 行的文件。我需要在其中搜索一个字段(SessionId 及其值)并打印其相应的值。
我已经编码以访问文件并逐行打印。在获取字段并打印其值时需要帮助。
文件示例行:
LastSessionTeardown.cc|598|Resolving:=N2BBSessionGateway.Factory
2013-12-23 06:03:22.488046 UTC VZ_QIP_S3_208 LastSessionTeardown.cc|636 <ERROR>:Failed to resolve SessionGateway:N2BBSessionGateway.Factory
Cause : user exception, ID 'IDL:omg.org/CosNaming/NamingContext/NotFound:1.0'
2013-12-23 06:03:22.488078 UTC VZ_QIP_S3_208 LastSessionTeardown.cc|640|Total resolved SessionGateways list(size):=0
2013-12-23 06:03:22.488098 UTC VZ_QIP_S3_208 LastSessionTeardown.cc|642|Out resolveSGWs::
2013-12-23 06:07:17.485959 UTC VZ_QIP_S3_208 StreamServiceMasterImpl.cc|989|In createStream::=77D23ECC4649571A367E9C314C4AA7AA
2013-12-23 06:07:17.487706 UTC VZ_QIP_S3_208 StreamServiceMasterImpl.cc|1036|StreamId: 77D23ECC4649571A367E9C314C4AA7AA **SessionId: C0A800F0DB2A::1387778933::1501** ContentId: vault22_12.mpg 1xGoid:
2013-12-23 06:07:17.505233 UTC VZ_QIP_S3_208 StreamServiceMasterImpl.cc|989|In createStream::=E30CC868325B51D288A8E2D95322B840
注意:该文件在指定字段的上方和下方有很多行
代码:
require "java"
include_class "java.io.BufferedReader"
include_class "java.io.FileReader"
include_class "java.lang.String"
fileReader = FileReader.new "protocoltiming.log.txt"
bufferReader = BufferedReader.new fileReader
str = bufferReader.readLine
while str
puts str.to_s
str = bufferReader.readLine
end
请帮助我添加到此代码中的内容?