Created
May 30, 2024 23:15
-
-
Save elico/73329c0d4b42b0c549a236c847fbe1ed to your computer and use it in GitHub Desktop.
filter-chr-rsc-for-import.rb
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
#!/usr/bin/env ruby | |
def filter_text_file(input_file) | |
# Read the input file content | |
content = File.read(input_file) | |
# Split the content into lines | |
lines = content.split("\n") | |
# Initialize a variable to track if we are inside a block to remove | |
inside_remove_block = false | |
filtered_lines = [] | |
# Process each line | |
lines.each do |line| | |
case line | |
when /^#/ | |
next | |
when /^\/disk/ | |
inside_remove_block = true | |
when /^\/port/ | |
inside_remove_block = true | |
when /^\/[a-zA-Z0-9]+/ | |
inside_remove_block = false | |
else | |
indise_remove_block = inside_remove_block | |
end | |
# Only add lines to filtered_lines if we are not inside any block | |
if inside_remove_block | |
next | |
else | |
filtered_lines << line | |
end | |
end | |
return filtered_lines.join("\n") | |
end | |
input_file = ARGV[0] | |
puts filter_text_file(input_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment