Created
July 27, 2015 16:33
-
-
Save jaksonmoura/6c5d5f2cca1982ccf213 to your computer and use it in GitHub Desktop.
A code I made for copying a part of the content in every 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
| notes = [] | |
| File.open("test.txt").each do |line| | |
| # record in a array var all the lines until find [fim] | |
| notes.push(line) | |
| if (line.include? "TOTAL DO EMPENHO:") | |
| # get total empenho value | |
| total_empenho = notes[-1] | |
| total_empenho = total_empenho.slice(18,11) | |
| # puts total_empenho | |
| # Remove last 2 lines from array | |
| puts notes | |
| line_emp2 = notes.pop(1).to_s | |
| notes.pop(1).to_s | |
| line_emp2 = line_emp2.slice(2, line_emp2.size - 6) | |
| # for each key until reach "TOTAL DO EMPENHO:" add total empenho at the begining | |
| notes.each do |note| | |
| note = total_empenho + " " + note | |
| File.open("out.txt", 'a+') {|f| f.write(note) } | |
| end | |
| File.open("out.txt", 'a+') {|f| f.write(line_emp2) } | |
| File.open("out.txt", 'a+') {|f| f.write("\n") } | |
| # clean up notes | |
| notes = [] | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment