首页 > 解决方案 > Ruby: Limit size writing to text file while using gsub

问题描述

Currently working on parsing out some error logs. I'm using ruby and the File library. I encounter about 381 instances of the word uid which I'm replacing with empty string using gsub.

enter image description here

However, when I replace the uid with new string only 9 instances of it are shown. I'm not sure if there is a size limit to what you can do with gsub.

file_input = ARGV[0]

text = File.read(file_input)

 replace = text.gsub(/uid/,'*********************************
 BEGINNING OF SUBMISSION *****************************************************')
File.open('testing.txt', "w") do |file|
  file << replace 
end

When I open up testing.txt the file is about 15 lines which is drastic contrast to the one being passed into file_input which is about 700 lines and has 381 mentiones of the word uid. Is there a limit?

标签: regexrubygsub

解决方案


推荐阅读