why 'grep' is used mostly for searching a pattern, why not 'awk'?

Here is the short and sweet explanation of this question.

grep is used to search for specific terms in a file which is different from awk, grep can't add/modify/remove the text in a specific file. But it's useful when we just want to search and filter out matches. awk can be considered as superset of grep. awk is more like a text processors which means it hasn't only have the ability to find out what you are looking for in text but it has ability to remove, add and modify the text as well.

Why not use awk?

We can use awk as well but it depends on what we want to do. There are things that are easier to do with one or the other. 

As per my knowledge, grep is easier to use in regards to search a particular pattern. For instance, in order to search both "easylinux" and "EASYLINUX" from test.txt,
using grep : grep -i  "easylinux" test.txt
using awk : awk 'tolower($0)~/easylinux/' test.txt OR awk -v IGNORECASE=1/easylinux/ test.txt (for GNU extension awk)

I would rather prefer to use grep than awk for searching a pattern. One more thing to note here is, grep highlights the searched pattern by default to red color but awk doesn't seem to do so.


Comments

Popular posts from this blog

MBR partitioning with 'parted' utility

Disk Partitioning: MBR vs GPT

Replace default splash screen in Yocto