0
我有一个包含n行的文件。我需要在其中搜索一个字段(SessionId及其值)并打印其相应的值。搜索文件中的模式并将其打印在jruby中
我编码访问文件并逐行打印。在获得领域和打印其价值方面需要帮助。文件
采样线:
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
请帮助一下什么是添加到此代码?
谢谢,但我得到这个错误文我上面的行添加到我的代码C:/jruby-1.6.8/lib/ruby/site_ruby/shared/builtin/javasupport/core_ext/object.rb:99警告:已经初始化了常量字符串 NoMethodError:未定义的方法'include?' for nil:NilClass (root)at C:\ FCSFinal \ latest_Automation \ Proj \ file.rb:16 – karthick23
我对'jRuby'不太熟悉,但是可以发布完整的代码吗?只需编辑您的上述帖子并复制粘贴您正在使用的代码即可。 –
恶劣请找代码, 需要的 “java” include_class代码 “java.io.BufferedReader中的” include_class代码 “java.io.FileReader” include_class代码 “java.lang.String中” 的FileReader = FileReader.new“StreamService。日志” bufferReader = BufferedReader.new的FileReader STR = bufferReader.readLine #puts str.to_s 而STR STR = bufferReader.readLine SESSION_ID = str.strip.scan(/ SessionID的:(+)\ S /)[0] [0] if str.include?(“SessionId:”) if session_id #s ession_id找到 else #session_id找不到 结束 结束 – karthick23