Unix day 4: Careful when using grep

How to prevent some common mistakes in grep

Ned Poplaski (CISSP)
1 min readMay 24, 2021

1. Searching for special characters

When you have to search some words using grep and those words have special characters in them, you have to be careful and use the -F parameter in grep command

You might want to search for a password which might contain a special character like % @ $ or ;

Lets take an example .

If you have a password file ( lets say pass.txt ) with hashed passwords ( lets say sha1 encryption )

It might contain lines like this :

sha1$e4da8$bf4546fa5fedfb7c1b42727b3f85208d07d95851

and if you look at the count of lines that have 'sha1$' in it ,

$ grep ‘sha1$’ pass.txt | wc -l
0

you will get 0 as an output. Thats because the $ is treated as a special character . ( In UNIX $ represents the beginning of a variable ). So to escape the special character we use -F parameter

Unix Solution :

$ grep -F ‘sha1$’ pass.txt | wc -l
23

Unix day — 3 : Removing dupes from a single file

--

--

Ned Poplaski (CISSP)

I share news and Lessons to make possible a safer cyber experience. cyber security educator. ex-McAfee, Consultant snyk.io,sonatype.