I am trying to create a rail template that will add code to files in specific line numbers. For example, I need to add a route to config / routes.rb
I tried sed, gsed (only the reason I am on mac and they say sed has problems with insert and add), in any case, I could not achieve the desired result.
Any help on this would be greatly appreciated.
I tried a few permutations of this command, but nobody is working, here is an example
run "gsed '3 a/This is it' config/routes.rb"
maybe another suggestion
EDIT ::
ok I took a break, and when I returned, after reading sed, I realized that I needed to write the stream back to the file, but I did it before,
run "gsed '2 a\ Add this line after 2nd line ' config/routes.rb > config/routes.rb"
but the routes file will be empty, so I tried using a different file name (new.routes.rb)
run "gsed '2 a\ Add this line after 2nd line ' config/routes.rb > config/new.routes.rb"
and it worked, so I know what to do now.
source share