Skip to content

Instantly share code, notes, and snippets.

@elico
Created May 30, 2024 23:15
Show Gist options
  • Save elico/73329c0d4b42b0c549a236c847fbe1ed to your computer and use it in GitHub Desktop.
Save elico/73329c0d4b42b0c549a236c847fbe1ed to your computer and use it in GitHub Desktop.
filter-chr-rsc-for-import.rb
#!/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