regex - 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
.
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?
解决方案
推荐阅读
- node.js - 在此示例中,如何使用 docker-compose 允许 2 个容器正确共享 .sock 文件?
- flutter - Flutter ButtonBar 儿童尺寸
- c# - 使用 svcutil 从 xsd 生成 DataContract 的问题
- python - 根据特定键合并字典列表
- junit - 在 JUnit 的 @After 中清理特定的测试用例方法
- ios - Mac 能识别 iPhone,Xcode 不能
- html - Twitter 时间线未加载
- firebase - 我可以使用 StreamBuilder 在 Firestore 中收听单个文档吗?
- r - data.table 中的 ifelse 函数不会产生正确的值
- firebase - 我可以根据不在数组中的值进行查询吗?