Reputation: 186662
I have a hunch that I should probably be using ack or egrep instead, but what should I use to basically look for
<?
at the start of a file? I'm trying to find all files that contain the php short open tag since I migrated a bunch of legacy scripts to a relatively new server with the latest php 5.
I know the regex would probably be '/^<\?\n/'
Upvotes: 1
Views: 4413
Reputation: 20691
find . -name "*.php" | xargs grep -nHo "<?[^p^x]"
^x to exclude xml start tag
Upvotes: 2
Reputation: 77786
If you're looking for all php short tags, use a negative lookahead
/<\?(?!php)/
will match <?
but will not match <?php
[meder ~/project]$ grep -rP '<\?(?!php)' .
Upvotes: 4
Reputation: 143304
Do you mean a literal "backslash n" or do you mean a newline?
For the former:
grep '^<?\\n' [files]
For the latter:
grep '^<?$' [files]
Note that grep will search all lines, so if you want to find matches just at the beginning of the file, you'll need to either filter each file down to its first line, or ask grep to print out line numbers and then only look for line-1 matches.
Upvotes: 0
Reputation: 186662
I RTFM and ended up using:
grep -RlIP '^<\?\n' *
the P argument enabled full perl compatible regexes.
Upvotes: 6
Reputation: 118665
grep '^<?$' filename
Don't know if that is showing up correctly. Should be
grep ' ^ < ? $ ' filename
Upvotes: 0