Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grep for literal strings

Tags:

grep

unix

You can use grep for that, with the -F option.

-F, --fixed-strings       PATTERN is a set of newline-separated fixed strings

That's either fgrep or grep -F which will not do regular expressions. fgrep is identical to grep -F but I prefer to not have to worry about the arguments, being intrinsically lazy :-)

grep   ->  grep
fgrep  ->  grep -F  (fixed)
egrep  ->  grep -E  (extended)
rgrep  ->  grep -r  (recursive, on platforms that support it).

Pass -F to grep.


you can also use awk, as it has the ability to find fixed string, as well as programming capabilities, eg only

awk '{for(i=1;i<=NF;i++) if($i == "mystring") {print "do data manipulation here"} }' file

cat list.txt
one:hello:world
two:2:nothello

three:3:kudos

grep --color=always -F"hello

three" list.txt

output

one:hello:world
three:3:kudos