how to pull out php code that contain certain words in ruby

蓝咒 提交于 2019-12-27 03:44:27

问题


Say if i have lots of php file (.php) and I'm only want to pull out block of code that contain certain words e.g. $this->te Any idea how I do it? using ruby would be better?

if ($attachments && count($attachments) > 0) {
 echo "\n\n{$this->te('Attachments')}:\n";
 ...

回答1:


You can just use grep for it:

grep '$this->te' -R *.php -n

If you want to do similar thing with Ruby, you can use something like:

Dir.glob('*.php').each do |x|
  File.read(x).split("\n").each_with_index do |line, n|
    puts "Found at #{x}:#{n+1}" if line["$this->te"]
  end
end


来源:https://stackoverflow.com/questions/31777853/how-to-pull-out-php-code-that-contain-certain-words-in-ruby

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!