0

I tried to use

find ./ -type f -name '*.php' -exec grep -slE '^asdasd' {} \;

and

find ./ -type f -name '*.php' -exec pcregrep -l '^asdasd' {} \;

But this commands found files, where 'asdasd' in beginning of lines, not of all text, for example:

File content:

qweqwe

asdasd

czczc

I want to find files only with this file content:

asdasd

qwdq

qwdad

(asdasd in beginning of all text)

fedorqui
  • 275,237
  • 103
  • 548
  • 598

2 Answers2

0

^(asdasd|qwdq|qwdad) to regexp only part you want to find OR ^(asdasd|qwdq|qwdad).* to regexp full line

Michał M
  • 618
  • 5
  • 13
0

With awk you can check if the first line matches whatever saying:

awk 'NR==1 && /pattern/' file

If you want to print its file name, then say:

awk 'NR==1 && /pattern/ {print FILENAME}'

To combine it with find and check if the first line starts with "asdasd", use:

find -type f -exec awk 'NR==1 && /^asdasd/ {print FILENAME}' {} \;
fedorqui
  • 275,237
  • 103
  • 548
  • 598
  • Ok! I will do it. Something else: Do you know why it impossible do with pcregrep? It seems pcregrep and grep work in multiline mode only. Or they ignore '^' – user2371331 Jun 30 '16 at 11:19
  • @user2371331 no, I don't know - I don't have experience with `pcregrep`, since `grep` alone and `awk` serve me very well. – fedorqui Jun 30 '16 at 11:24