Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby txt解析器-在条件为on时输出以下行_Ruby_Parsing - Fatal编程技术网

Ruby txt解析器-在条件为on时输出以下行

Ruby txt解析器-在条件为on时输出以下行,ruby,parsing,Ruby,Parsing,我有一个如下结构的文本文件: ---------------------------------------- ---------------------------------------- All Events Information: 1 : Timestamp: 08.11.2017 01:46:10 Message: DEBUG, Thread ID:12,63645705970991641611 - Request: POST https://some.url.com:8080/ap

我有一个如下结构的文本文件:

----------------------------------------
----------------------------------------
All Events Information: 1 : Timestamp: 08.11.2017 01:46:10
Message: DEBUG, Thread ID:12,63645705970991641611 - Request: POST https://some.url.com:8080/api/Customers/
{"json":"someValue"}
对于包含请求URL的每条消息
“/api/Customers”
,我想输出以下行
{“json”:“someValue”}
。如果没有,它应该跳过整个街区

这是我到目前为止所拥有的。它正确地放置了行,但我想得到以下行:

File.open("my_file.log", "r").each_line do |line|
    if line.include? "POST https://some.url.com:8080/api/Customers/\r"
        p line
    end
end

下面是一个非常简单的解决方案:

def test
  show_next_line = false
  File.open("/home/gergra/code/test/my_file.log", "r").each_line do |line|
    if show_next_line
      show_next_line = false
      puts line
    end
    if line.include? "POST https://some.url.com:8080/api/Customers/"
      show_next_line = true
    end
  end
end

谢谢,但这并没有做到,因为我仍然在这一行的循环中,所以它只是输出相同的结果。如果您删除include参数中的“\r”,我需要转到下一行。是否有效?否,我仍在同一行。不知何故,我需要“下一个”去工作。对不起,我很匆忙。所以,这是正确的版本