Difference between revisions of "Grep"

From wikieduonline
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 16: Line 16:
 
:<code>[[grep --exclude|--exclude]]</code>
 
:<code>[[grep --exclude|--exclude]]</code>
 
:<code>[[--exclude-dir]]</code>
 
:<code>[[--exclude-dir]]</code>
 +
::<code>grep -r --color=always -n -H --exclude-dir='.*'</code>
 
:<code>[[--line-buffered]]</code>
 
:<code>[[--line-buffered]]</code>
 
   -H, --with-filename
 
   -H, --with-filename
Line 64: Line 65:
 
* [[Amazon CloudWatch Logs Insights]]
 
* [[Amazon CloudWatch Logs Insights]]
 
* [[Logs]]: [[ElasticSearch]] and [[OpenSearch]]
 
* [[Logs]]: [[ElasticSearch]] and [[OpenSearch]]
 +
* [[yq]]
 
* <code>[[logcli]]</code> for [[Loki]]
 
* <code>[[logcli]]</code> for [[Loki]]
 
<pre>
 
<pre>

Latest revision as of 14:53, 25 August 2024

grep[1] is a command for searching plain text data sets for lines that match a regular expression.


~/.bash_profile

alias grep='grep --color=auto'

Common options[edit]

-o, --only-matching
-a, --text equivalent to --binary-files=text
-i
-I Ignore binaries
-r
-v
-w
--exclude
--exclude-dir
grep -r --color=always -n -H --exclude-dir='.*'
--line-buffered
 -H, --with-filename

Examples[edit]

Search for a pattern: TEXT="OTHER_TEXT"

Search for a pattern: TEXT="OTHER _TE XT" including spaces:

  • grep -o 'TEXT="[ a-zA-Z0-9_]*"' index.html

Search in hidden folders:

  • grep -ir your-search * .[^.]*

End of line:

  • grep your-search$

Add line:

  • grep -qxF 'your text "additional text"' yourfile.txt || echo 'your text "additional text"' >> yourfile.txt


Related[edit]

 [[:alpha:]]
 [[:alnum:]]
[[:digit:]]

See also[edit]

  • http://man7.org/linux/man-pages/man1/grep.1p.html
  • Advertising: