Created
February 26, 2025 08:13
-
-
Save azelenets/b0aeebae689209bb07c1c16e09bead98 to your computer and use it in GitHub Desktop.
Read CSV files from fir and group by last column value (HTTP response code)
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
| Dir.foreach('broken_links_data') do |filename| | |
| next if filename == '.' or filename == '..' | |
| grouped_data = {} | |
| File.foreach("broken_links_data/#{filename}") do |line| | |
| line_data = line.split(',') | |
| grouped_data[line_data.last.chomp] ||= [] | |
| grouped_data[line_data.last.chomp] << "#{line_data[0..2].join(',')},\"#{line_data[3..-2].join(',')}\"" | |
| end | |
| grouped_data.each_key do |key| | |
| Dir.mkdir("broken_links_data_grouped/#{key}") unless File.exist?("broken_links_data_grouped/#{key}") | |
| File.write("broken_links_data_grouped/#{key}/#{filename}", grouped_data[key].join("\n")) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment