File Search Tool
File search tools: grep, egrep, fgrep
The following describes grep and sed commands.
First line anchor ^ PATTERN
Anchor at the end of the line $
\ <The first Separator of the PATTERN word is enclosed in single or double quotation marks.
PATTERN> end anchor
. Match any single character does not match the carriage return character
* Match previous characters 0 to any time
. * Match any character of any length
Regular Expressions work in greedy mode: matching strings that match the pattern as long as possible
Exact match count
? Match the previous character 0 times or 1 time;
\ {M, n \} At least m times. Up to n times
\ {0, 5}
[] Match any single character in the specified range
[^] Match any single character out of the specified range
--I that does not match the value of-v ignores the case sensitivity.
-R
-B follows the number n and displays the first n rows.
-N rows after A is displayed
-C: show n rows before and after
-O: display the matched string instead of the row to be searched.
-E supports extended Regular Expression
\ (\) \ 1, reference content in brackets
Extended Regular Expression grep-E
{} () | (OR) + (match once)
Standard Input: keyboard is represented by 0.
Standard output: monitor is represented by 1.
Standard Error output: monitor is represented by 2
Redirection:
> Output redirection overwrite cannot be returned
> Append redirection is equivalent to re-writing
You can use set to set whether to use output redirection:
Set-C unavailable>
Set + C continue to use>
Error output redirection: 2> direct only the correct output
2> aggravated targeting
Integrate the correct and wrong data streams in a file: &>
After the command is executed in Linux, there is a return code.
Successful execution: 0 error: 1-255
Returns echo $?
/Dev/null, bit bucket, bit bucket
<Input redirection
<
Cat>/tmp/a. out <END
MPs queue: |
Use the output of the previous command as the input of the previous command.
COMMAND1 | COMMAND2 | COMMAND3
Sed
Use Basic Regular Expressions
Stream editor row editor
Non-interactive Editor
No destructiveness
Command:
D. Delete rows;
Usage: sed "ADDR1, ADDR2/command" inputfile
Indicates a range.
You can also use character matching:
/PATTERN/command
/PATTERN1/,/PATTERN/
P: displays the rows that match the output mode twice, that is, the print command.
-N: only the content matching the mode is displayed, that is, set-n...
A \ add a line \ n after a matched row
The I \ command cursor matches above the line
! Returns the inverse of the matching condition.
S search replacement
S @ g I flag
Common sed options:
-N: quiet
-E:-e ''' multiple conditions are specified at a time.
-I: You can directly modify the original file.
-F: The sed script can be read.
This article is from the "linux learning" blog