-2

my file is text.txt with content

resources :albums, except: [:new, :edit, :destroy] 
resources :conversation_replies, except: [:new, :edit, :destroy] 
resources :authors, except: [:new, :edit, :destroy] 
......... 

Now, I want to delete a line in this file. example, I want delete line with content with the characters such as: conversation_replies

Please help me. thank you very much

Khaihkd
  • 307
  • 2
  • 6
  • 1
    in ruby exactly, or enough bash? – Малъ Скрылевъ Feb 17 '14 at 07:04
  • You can defiantly find your answer here: [First][1] [Second][2] [1]: http://stackoverflow.com/questions/16638667/how-do-i-remove-lines-of-data-in-the-middle-of-a-text-file-with-ruby [2]: http://stackoverflow.com/questions/17854731/deleting-a-line-in-a-text-file – Bharat soni Feb 17 '14 at 07:19
  • @jvperrin Are you aware it's the same guy? He is trying to programatically delete entries in his `routes.rb` file. He was told it's just a text file, so now we have this... Check out his example text. – Substantial Feb 17 '14 at 08:04

2 Answers2

0
system("cat youfile | grep -v conversation_replies > yourfile.bak)
system("mv youfile.bak yourfile")
lalameat
  • 754
  • 3
  • 10
0

ruby code in txt file?

Pretty much hard-coding..

  1. Read and store content into a variable using File.read(*path*)
  2. Split contents based on /n (new line)
  3. Loop each line and split then match the content
  4. On true push empty space, join file with \n
  5. Save and close the file.
Nithin
  • 3,679
  • 3
  • 30
  • 55