Last active
January 12, 2018 08:26
-
-
Save joeeeeey/10be1ed8922b9b5f55b322a2df95892c to your computer and use it in GitHub Desktop.
Ruby read big file, filter and delete line.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| output_file_path = "output_file_path" | |
| input_file_path = "input_file_path" | |
| open(input_file_path, 'r') do |f| | |
| open(output_file_path, 'w') do |f2| | |
| f.each_line do |line| | |
| if line != "\n" # logic here | |
| f2.write(line) | |
| end | |
| end | |
| end | |
| end | |
| # If need to replace old file bu new file | |
| FileUtils.mv output_file_path, input_file_path |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
reference