user1210218
user1210218

Reputation: 27

grep first n rows, return file name only

I can do the following to search for what I need and return the file name: grep -l "mysearchstring" ./*.xml However the files I am searching are huge so this takes forever. The string I am searching will appear in the first 200 rows so how can I search only the first 200 rows and still return the file name? Thanks

Upvotes: 1

Views: 65

Answers (1)

anubhava
anubhava

Reputation: 785058

You can do:

for file in *.xml; do
   head -200 "$file" | grep -q "mysearchstring" && echo "$file"
done

Upvotes: 5

Related Questions