0

I am trying to find every file that has

$status=='access'||!Yii::app()->user->isGuest

and replace it with

$status=='access'

Is there an easy way to accomplish this in linux. I tried using the following example (which replaces windows with linux), but couldn't get it to work. It doesn't throw any errors.

grep -rl 'windows' ./ | xargs sed -i 's/windows/linux/g'

grep -rl "\$status=='access'||\!Yii::app()->user->isGuest
" ./ | xargs sed -i 's/\$status=='access'||\!Yii::app()->user->isGuest
/$status=='access'/g'
Sam Kingston
  • 817
  • 1
  • 10
  • 19
  • 1
    There are double-quotes inside the sed that sed is trying to match, but not in the file(s). – Jeff Y Oct 11 '15 at 14:12
  • Originally, I didn't have double quotes. I received an error. Is it because sed can't escape the single quotes the way I have written it? I have edited my post to show what I tried. – Sam Kingston Oct 11 '15 at 14:14
  • @SamKingston: You need to escape the single quotes, since the shell doesn't allow single quotes between single quotes, even when preceded by a backslash (or at least, bash doesn't). try `"s/\\\$status=='access'||\!Yii::app()->user->isGuest/\$status=='access'/g"` – Hasturkun Oct 11 '15 at 14:22
  • 1
    http://stackoverflow.com/questions/24509214/how-to-escape-single-quote-in-sed – Jeff Y Oct 11 '15 at 14:26

0 Answers0