From 62b9faa6845e1370d8bd6f4a9d84fa91132d7524 Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Sat, 25 Feb 2023 18:44:50 +0100 Subject: [PATCH] Added command to highlight numbers in a text --- knowledge base/grep.md | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/knowledge base/grep.md b/knowledge base/grep.md index 932019a..07cda36 100644 --- a/knowledge base/grep.md +++ b/knowledge base/grep.md @@ -3,20 +3,23 @@ ## TL;DR ```sh -# base search -grep 'pattern' path/to/search +# Basic search. +grep 'pattern' 'path/to/search' -# recursive search -grep -R 'pattern' path/to/search/recursively -grep -R --exclude-dir excluded/dir 'pattern' path/to/search/recursively # gnu grep >= 2.5.2 +# Search recursively. +grep -R 'pattern' 'path/to/search/recursively' +grep -R --exclude-dir 'excluded/dir' 'pattern' 'path/to/search/recursively' # gnu grep >= 2.5.2 -# show line numbers -grep -n 'pattern' path/to/search +# Show line numbers. +grep -n 'pattern' 'path/to/search' -# parallel execution -# mind the files with spaces in their name -find . -type f | parallel -j 100% grep 'pattern' -find . -type f -print0 | xargs -0 -n 1 -P $(nproc) grep 'pattern' +# Multiple parallel searches. +# Mind files with spaces in their name. +find . -type f | parallel -j +100% grep 'pattern' +find . -type f -print0 | xargs -0 -n 1 -P "$(nproc)" grep 'pattern' + +# Highlight numbers in strings. +grep --color '[[:digit:]]' 'file.txt' ``` ## Grep variants