Created
May 28, 2015 08:02
-
-
Save ymkjp/6a9866dba1880008a642 to your computer and use it in GitHub Desktop.
Multiline editing instead of painful sed or awk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
# Usage: | |
# SRC_FILE="nginx.conf" DIST_FILE="nginx.conf~" ruby rough_sed.rb | |
from =<<EOS | |
log_format main '$remote_addr - $remote_user [$time_local] ' | |
'"$request" $status $bytes_sent ' | |
'"$http_referer" "$http_user_agent" ' | |
'"$gzip_ratio"'; | |
EOS | |
to =<<EOS | |
log_format main '$remote_addr - $remote_user [$time_local] $status ' | |
'"$request" $body_bytes_sent "$http_referer" ' | |
'"$http_user_agent" "$http_x_forwarded_for"'; | |
EOS | |
string = File.read(ENV["SRC_FILE"], encoding: Encoding::UTF_8) | |
result = string.sub(from, to) | |
File.write(ENV["DIST_FILE"], result) | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment