Commonly used · Reading and processing text
grep: Filter text by pattern
Syntax
grep [parameter] mode [file…]Options
-i- Ignore case
-n- Show line number
-v- Reverse filtering
-c- Count matching rows
-r / -R- Search files recursively
-E- extended mode
-F- fixed string
-l- Show only matching files
-e- Specify mode
Examples
grep -n ERROR logs/app.logUsage and sandbox support
The exit code for no match is 1. The sandbox uses the JavaScript regular subset, which is not exactly equivalent to GNU grep.
Hands-on exercises
- Filter out error logsEveryday
- Label errors with line numbersEveryday
- Save filtered errorsAdvanced
- Leave a fault record that can be handed overAdvanced
- List Challenge ① Filter recordsAdvanced
Related commands
catRead and concatenate textlessRead text in pagesmoreView text in pagesheadRead the first few linestailRead last few linesfindFind paths by name or typewcCount lines, words and bytessortSort lines of textuniqMerge adjacent duplicate rowscutExtract columns or characterstrReplace or delete characterssedReplace text or select linesawkExtract structured text fieldsdiffCompare two text filesvimEdit files in terminalnanoModify files with a simple editornlNumber lines of texttacOutput lines of text in reverse orderrevReverse characters line by linepasteSplicing text columns horizontallycommCompare sorted listscmpCompare files to see if they are the sameexpandConvert Tab to spacesunexpandConvert leading spaces to TabfoldWrap long textrgFast recursive text searchjqHandle JSONyqHandle YAMLjoinMerge sorted tables by common fieldsfmtReformat paragraphs word by wordcolumnArrange text tablestringsExtract printable text from binaryodView file byte representationhexdumpShow hexadecimal bytesxxdView or restore hex dumpiconvConvert text encodingdos2unixConvert Windows to newlinesplitSplit file by linescsplitSplit text by patternbcEvaluate a numeric expression