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
精彩评论