LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Request for grep -F example (https://www.linuxquestions.org/questions/linux-newbie-8/request-for-grep-f-example-884862/)

linutzy 06-06-2011 02:33 PM

Request for grep -F example
 
Giving Linux a serious look again and starting from the beginning.

I read the man pages for grep -F but can't put my head around it.
I know it is like fgrep, but I was wondering if there is a real world use for it when searching through a file.

I did the standard grep -F in google but I'm not really able to find any details other then the:

-F, --fixed-strings
Interpret PATTERN as a list of fixed strings, separated by new-
lines, any of which is to be matched.

I just don't know how you would use it, kinda stumped, but very curious. It is however cryptic for me :-(

hotspur919 06-06-2011 03:19 PM

Heres something for you.


See explanation below. Hope it helps. i suppose it would be useful to find certain lines of code in a file perhaps.

1. fgrep '***' *



2 fgrep '[ ] * ? $' filex



EXPLANATION

1.

Displays any line containing three asterisks from each file in the present directory. All characters are treated as themselves (i.e., metacharacters are not special).
2.

Displays any lines in filex containing the string enclosed in quotes.


Definition: metacharacter: A character that is used to carry a special meaning, such as a caret (^, beginning of line), a dollar sign ($, end of line), or an asterisk (*, match any character). To use one of these characters without special meaning, you must either precede it with a backslash () or enclose it within quotation marks. Bypassing the special meaning of a metacharacter is called escaping or quoting the character.= fgrep bypasses the special meaning of these characters:-)


All times are GMT -5. The time now is 06:43 AM.