【问题标题】:How to capture next tine after the certain previous line in the node.js如何在node.js中的上一行之后捕获下一次
【发布时间】:2021-12-24 12:51:34
【问题描述】:

日志文件有多次发生的某些字符串。我需要使用 node.js 为所有出现的前一个字符串捕获下一行。 例如文件内容:

Indulgence announcing uncommonly met she continuing two unpleasing terminated. Now busy say down the shed eyes roof paid her  
Compile Error  
./aaarty/bbb/cfvcc/dddhjklpi  
Course suffer to do he sussex it window advice. Yet matter enable misery end extent common men should. Her indulgence but assistance favourable cultivated everything collecting  
Compile Error  
./asshtyd/wrfber/ghn/fffh/gh/ikjmlk  
Extended kindness trifling remember he confined outlived if. Assistance sentiments yet unpleasing say  
Compile Error  
./cc/wwwasftbb/kkk/tgfh/pioqascfg/qqq  
Open they an busy they my such high  strong text  

使用 node.js,我需要使用字符串“编译错误”捕获行后的每一行

【问题讨论】:

    标签: javascript node.js filesystems fs readline


    【解决方案1】:

    我明白了:

    var fs = require('fs');
    var array = 
    fs.readFileSync('mylogfile.txt').toString().split("\n");
        for(let i in array) {
           if (array[i] == "Compilation Error")
              {
                let k = parseInt(i)+parseInt(1)
                console.log(array[k])
              }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-02-10
      • 1970-01-01
      • 2017-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多