I have text file which contains the below hidden characters which I got with sed.
If the file size is not too big, you can read the whole file contents in, and then remove all the escaped sequences.
content = File.read('your_input_file_path') content.gsub!(/\033\[(?:H|2J)/, '') content.split(/\r?\n/).each do |line| # process line end
You can generalize the Regex used according to the escaped sequence pattern. In you example, it seems it's
\033[ followed by an optional digit, and then a letter. Which can be updated as: