开发者

How to modfiy environment.rb through sh script? (i.e. modify line in file through script?)

开发者 https://www.devze.com 2022-12-16 19:39 出处:网络
I\'m trying to write a sh script to make a rails apps, however due to different conflict, I need to modify my environment.rb file to c开发者_如何学Comment out the rails version. So my question is how

I'm trying to write a sh script to make a rails apps, however due to different conflict, I need to modify my environment.rb file to c开发者_如何学Comment out the rails version. So my question is how do I had '#' to line 8 of environment.rb?


There are many ways, but sed is the first hammer that came to mind:

sed 's/^\(RAILS_GEM_VERSION.*\)$/# \1/' -i '.backup' config/environment.rb

Or even in ruby:

ruby -pi  -e 'print "# " if $_ =~ /^RAILS_GEM_VERSION/' config/environment.rb


to comment line 8

awk 'NR==8{$0="#"$0}1' config/environment.rb >temp
mv temp config/environment.rb 

to comment line with RAILS_GEM_VERSION

awk '/RAILS_GEM_VERSION/{gsub(/^RAILS_GEM_VERSION/,"#RAILS_GEM_VERSION") }1' config/environment.rb >temp
mv temp config/environment.rb

and depending on where you want to add config.gem "newrelic_rpm", say you want to add at the end of the file, then just use >>

echo 'config.gem="newrelic_rpm"' >> config/environment.rb
0

精彩评论

暂无评论...
验证码 换一张
取 消