问题
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