Skip to content

Instantly share code, notes, and snippets.

@jjam3774
Last active July 29, 2020 23:04
Show Gist options
  • Save jjam3774/7a56388df47b74fc58a1 to your computer and use it in GitHub Desktop.
Save jjam3774/7a56388df47b74fc58a1 to your computer and use it in GitHub Desktop.
This will replace strings in a file.
#!/usr/bin/ruby -w
def replace_ref(file, fileindx, &directive)
old_stdout = $stdout
argf = ARGF.clone
argf.argv.replace [file]
argf.inplace_mode = fileindx
argf.each_line() { |line|
yield line
}
$stdout = old_stdout
end
File.open('files').each {
|i|
puts i
begin
replace_ref i.chomp, '.bk' do |line|
puts i + " Is being changed..."
line = line.gsub(/\/common\/js\/extern\/omniture\/s_code.js/,"/js/extern/omniture/s_code.js")
print line
end
rescue
puts i.chomp + " Does not exist...".upcase
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment