bash - How to give a pattern for new line in grep?

try pcregrep instead of regular grep: pcregrep -M "pattern1.*\n.*pattern2" filename the -M option allows it to match across multiple lines, so you can search for newlines as \n.... Read More

regex - How to invert a grep expression

Use command-line option -v or --invert-match, ls -R |grep -v -E .*[\.exe]$\|.*[\.html]$... Read More

linux - How do I grep recursively?

grep -r "texthere" . The first parameter represents the regular expression to search for, while the second one represents the directory that should be searched. In this case, . means the current dir... Read More

How can I have grep not print out 'No such file or directory' errors?

You can use the -s or --no-messages flag to suppress errors. -s, --no-messages suppress error messages grep pattern * -s -R -n... Read More

regex - How to find patterns across multiple lines using grep?

Grep is not sufficient for this operation. pcregrep which is found in most of the modern Linux systems can be used as pcregrep -M 'abc.*(\n|.)*efg' test.txt where -M, --multiline allow patterns to... Read More

How to "grep" for a filename instead of the contents of a file?

You need to use find instead of grep in this case. You can also use find in combination with grep or egrep: $ find | grep "f[[:alnum:]]\.frm"... Read More

unix - How to truncate long matching lines returned by grep or ack

You could use the grep option -o, possibly in combination with changing your pattern to ".{0,10}<original pattern>.{0,10}" in order to see some context around it: -o, --only-matching Sh... Read More

unix - changing chmod for files but not directories

A find -exec answer is a good one but it suffers from the usually irrelevant shortcoming that it creates a separate sub-process for every single file. However it's perfectly functional and will only... Read More

search - grep for special characters in Unix

Tell grep to treat your input as fixed string using -F option. grep -F '*^%Q&$*&^@$&*!^@$*&^&^*&^&' application.log Option -n is required to get the line number, grep -Fn '*^%Q&$*&^@$&*!^@$*&^&^*&^&'... Read More

unix - How does grep run so fast?

Assuming your question regards GNU grep specifically. Here's a note from the author, Mike Haertel: GNU grep is fast because it AVOIDS LOOKING AT EVERY INPUT BYTE. GNU grep is fast because it EXECUTE... Read More