sens_epro
sens_epro

Reputation: 399

How can I grep for a word in a specific part of a file?

How to grep a word in 100 to 200 lines from file using grep and sed?

Upvotes: 1

Views: 290

Answers (3)

tchrist
tchrist

Reputation: 80423

If you don’t mind using perl instead, the most straightforward solution is

$ perl -nle 'print if 100 .. 200 && /regex/'  somefile

Upvotes: 0

ernix
ernix

Reputation: 3643

You can use awk.

cat "$FILE" | awk 'NR>=100 && NR<=200 && /regex/'

Upvotes: 0

Navi
Navi

Reputation: 8756

  grep "word" file(s)

for instance

 grep word *

searches for word in all files in the current directory. To print 100 -200 line do

 sed -n '100,200p'

So combined you get

 sed -n '100,200p' *|grep word

Upvotes: 2

Related Questions