Search a file for a specific word

If you want to search a file for a line that includes a specific word then simply issue the command

grep science science-paper

That would search the file science-paper for the word science and show the line where the word is located

If you want to ignore case sensitivity, in that if you issue the command

grep ScIeNce science-paper

then the word science would still be returned, then simply include the argument

-i

So the command would be

grep -i ScIeNce science-paper

 

Other grep arguments include

-v display lines that don’t match
-n precede each matching line with the line number
-c print only the number of matched lines

To issue the grep command with multiple arguments just bunch all the arguments together like this

grep -in science science-paper

that would display each line precede with the line number as we include the -n argument as well

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.