Skip to content

Instantly share code, notes, and snippets.

@kotp
Forked from anonymous/For_Goff.rb
Created March 2, 2012 06:14
Show Gist options
  • Save kotp/1956158 to your computer and use it in GitHub Desktop.
Save kotp/1956158 to your computer and use it in GitHub Desktop.
It's a description
=begin
notes: I need to use readlines method....also I need to make a method that accepts user input or accepts a directory as an arg and maybe includes input validation to make sure that the directory includes "' '" or maybe easier include the single quotes in the method...
end
read_source_lines_from_file_to_a = File.read('C:\Users\demon002\text.txt').each_line.to_a
read_source_lines_from_file_to_a[5] = "test test inserted word test test"
File.open('C:\Users\demon002\text.txt', "w") do |inst|
inst.puts read_source_lines_from_file_to_a.to_s
end
File.read('C:\Users\demon002\text.txt')
=end
array_of_lines = IO.readlines('text.txt')
array_of_lines.each do |line|
line.gsub('word', 'insert word')
end
result = array_of_lines.join("\n")
IO.write('text.txt', result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment