Grep command in Unix/Linux is the short form of ‘global search for the regular expression’. The grep command is a filter that is used to search for lines matching a specified pattern and print the matching lines to standard output. Piping to wc util is slow: ~ $ time grep and tmp/a/longfile.txt | wc -l2811real 0m0.097s userContinue Reading
Tag: grep
How to count number of files in directory (Bash)
This recipe based on ls output format. When you list a directory, you see file types in the first column. “-” – for a plain file, “d” is for a directory. You can learn more about files in Unix in this article: “File and directory permissions in Linux / FreeBSD / MasOS“. Also we useContinue Reading
How to find a text in files on Linux / Unix in terminal
You may think, that you should use the “find” utility to … find. But you need the “grep”. grep -rnw ‘/path/to/directory/’ -e ‘pattern’ Where -r is recursive (-R for using symbolic links),-n is line number,-w stands for match the whole word. And it’s pretty common – grep is perfect for searching something in files. And you can use findContinue Reading