I am using linux commands to generate a file "a.txt" . Now I need to read the first word of file "a.txt" and update an existing file called "b.txt". I will search a word called "/fill " in b.txt and replace it with the word read from a.txt Below is the code
bash 'example' do
code <<-EOH
cat ex.txt >> a.txt
EOH
end
test = /#{'cat /a.txt'}/
file_names = ['/b.txt']
file_names.each do |file_name|
text = File.read(file_name)
new_contents = text.gsub(/fill, test)
puts new_contents
File.open(file_name, "w") {|file| file.puts new_contents }
- With the help of linux command "cat ex.txt >> a.txt " I am putting the content of ex.txt to a.txt.
- After this I want to read the file a.txt with test = /#{'cat /a.txt'}/. Example a.txt contains "azure" word
- Now in b.txt I want to search for a word "/fill" and replace with content read in step 2 from b.txt file ie azure
- The problem is instead of replacing /fill with azure, /fill is getting replaced with cat /a.txt. Hope its clear now
Can you please help here