Linux command of the day

I needed to kill all of the target=_blank’s in a site:

grep -lr ' target="_blank"' . | xargs sed -i -e 's/\starget=\x22_blank\x22//g'

Ran in about 1 second over ~750 files (unusually fast for grep on my system).


  • guyblade

    Doesn’t that exclude things like ‘ target = “_blank”‘ and ” target = ‘_blank'”? I would suggest the regex /target\s*=\s*[\x22\x27]_blank[\x22\x27]\s*/. Though the correct way might be /target\s*=\s*([\x22\x27])_blank\1\s*/ but I am less sure about using backreferences outside of perl.

    • Lissa

      Yeah, it does exclude those, but I had a cheat: the code was all written in-house by my team, so I knew that 99.95% of the cases would be regular.

      Plus, backreferences frighten me a bit. It’s my shameful secret. 😛