grep -F, what is it good for?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep -F, what is it good for?
# 1  
Old 04-14-2012
grep -F, what is it good for?

Hello, Unix-Forums!

I have a simple question:

I cannot see any difference between
Code:
grep [expression] [file]

and

Code:
grep -F [expression] [file]

The help says that "PATTERN is a set of newline-separated fixed strings"

Isn't this default anyway?
I'm a little bit confused.
# 2  
Old 04-14-2012
The key word is "string" as opposed to pattern. Fgrep, or grep -F doesn't do any regular expression matching. Consider searching for the string .*.* in a file:

Code:
grep -F ".*.*" filename
grep "\.\*\.\*" filename

See the difference? Using -F allows the search criteria to be free of any escape characters.

Also, if you are searching for strings, rather than patterns, I believe that using the -F option might result in quicker searches because there isn't any regular expression work involved with the scanning of each input record (I reserve the right to be wrong on that assumption).
This User Gave Thanks to agama For This Post:
# 3  
Old 04-14-2012
Ah, so using -F avoids interpreting * as a wildcard?

That means it would threat everything as a normal letter instead of using special functions like *.

Did I get it?
# 4  
Old 04-14-2012
Yes. Create a file and try it out; it's always fun to experiment with things like this.
# 5  
Old 04-14-2012
Also, if you do not need regular expression, a literal string match using grep -F can be quite a bit faster...
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. What is on Your Mind?

What is good?

Hello everyone, I am using centos, 1) solaris is free right? 2) I want to learn solaris and install it in a computer that I am mounting, I would like know what is strong in solaris and if do it is wise. I am programmer python, learning machine and programming in general,..any help thanks,.. (6 Replies)
Discussion started by: gitac
6 Replies

2. Shell Programming and Scripting

Inconsistent `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l`

i have this line of code that looks for the same file if it is currently running and returns the count. `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l` basically it is assigned to a variable ISRUNNING=`ps -eaf -o args | grep -i sfs_pcard_load_file.ksh |... (6 Replies)
Discussion started by: wtolentino
6 Replies

3. UNIX for Dummies Questions & Answers

Is there a good way to grep multiple directories without --include?

Hello. I consider myself a journeyman Unix user. I can handle most day to day tasks and have created some fairly complicated command queries, but this problem has defeated me so far. Any help would be greatly appreciated! We keep an archive in the file system with a directory structure in... (5 Replies)
Discussion started by: pauliesyllabic
5 Replies

4. Shell Programming and Scripting

Good Example on $|

I am trying to learn how to use the predefined var. I did read perlvar - perldoc.perl.org but like much of the perl docs, I just dont "see" the explanation. Can someone explain its usage to me. Id like to buffer printing on occasion. Thanks in advance. (1 Reply)
Discussion started by: popeye
1 Replies

5. Shell Programming and Scripting

MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else

Hi Guys, I need to set the value of $7 to zero in case $7 is NULL. I've tried the below command but doesn't work. Any ideas. thanks guys. MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else { print $7}}' ` Harby. (4 Replies)
Discussion started by: hariza
4 Replies
Login or Register to Ask a Question