Today, Mayuyu Some of the commands that are commonly used in Linux.1. grep commandgrep is used to filter what you need, and the syntax is as followsgrep Mayuyu--colorFilters out all rows that contain Mayuyu, and grep also supports regular expressions.2. SED commandThere are two main issues when editing a file using the normal VIM editor (1) When the file is relat
====================================Grep [Option] basic regular expression [file]
1. Option-C: only counts matching rows.-I is case insensitive (single character)-H does not display file names (when multiple files are used)-L only output file names (when multiple files are used)-N: display matching rows and row numbers-S does not display error messages-V: Display All rows that do not contain matched text
2. query multiple filesGrep "sort" *. DocGr
Like the following text:ABCD 1234 FDS2011 5501023 832er 1231
The request is processed as follows:ABCD 1234 FDS2011 550total1:1023 Total2:832er 12end
Determine if the last line of text is preceded by the first column with Total1: The second column plus Total2: The third column is followed by minus two characters followed by the end.
Implemented using SED and awk, respectively.Sed:
Copy Code code as
All said that the SED awk maintenance personnel's necessary tools, starting today to organize related notes, first of all to meet these two things.Commonality: Using the same syntax [Address]/pattern/action/flagis a character stream-oriented, read input from a bank at a time, and output to standard output, which is input-drivenare pattern-matching using regular expressions.Allows the user to specify instruc
GrepThe grep command in a Linux system is a powerful text search tool that uses regular expressions to search for text and match lines to print.Command syntax:Usage:grep [-ABCDEFGHHIIJLLMNOOQRSSUVVWXZ] [-A num] [-b num] [-c[num][-E Pattern] [-F file] [--binary-files=value] [--color=when][--context[=num]] [--directories=action] [--label] [--line-buffered][--null] [Pattern] [File ...]Command instance:-C: Calculates the number of rows to match and displa
SED: line editing toolssed [option] ... ' Address edit command ' filename ...Address format:Start_line[,end_line] #需要编辑的行号/patten1/,/patten2/#第一次被pattern1匹配到的行开始 to all rows between the end of the line to which the first pattern2 is matched;/pattern/#对被pattern匹配到的行进行相关操作No address #对全文进行操作The pattern above is usually a regular expressionEdit commandP: PrintD: DeleteI text: Above the line, text is an example of what is inserted:
Summary: The regular expressions for the two commands are distinguished by ' single quotation marks.The output variable name is quoted in single quotes, and the output variable value is quoted in double quotes, which is generally common in bash scripts.To use a variable value in a bash script, enclose the double quotation markawk usage:Reference URL: http://www.cnblogs.com/xudong-bupt/p/3721210.htmlCommand form:awk [-f|-f|-v] ' begin{}//{command1; Command2} end{} ' fileSeparate the Product_uuid
Encountered a problem when querying the log found that there are many files printed on the server, each of which stores a portion of the log, the log needs to be sorted by time and all logs are displayed.Original command:grep-h searchcontent */*log The search results will show all the contents in the following format:File1.log: time .... File2.log: time .... Because the log after the file name also contains :, so the use of separators : The method of separating sorting is not feasible, at this t
#/bin/bash# sort the data inside the text awk ' begin{rs= ', '}{print $0}end{} ' C + + Sorts large amounts of data inside the text (shell,c++,fopen,awk,sed)
1.The question:The sample text is as follows:AaaaabbbbbcccccdddAaaaabbbbbcccccThe following results are expected:Aaaaa|bbbbb|ccccc|dddAaaaa|bbbbb|cccccMatching requirements:I want a "|" to be inserted between every 5 characters, and if the number of characters in the line is exactly 5, the "|" is not inserted at the end of the line.Jie Yi:' s# (. { 5}) #\1| #g' t1shell.txt |sed 's#|$# #g'aaaaa|bbbbb|ccccc| DDDAAAAA|cdefg|bbbbc| ccccdddddSolution Two
Label: file sp c r BS as program D Method
Method for obtaining the process ID by shell:
I know there are three things I have learned and practiced:
PS-A | grep "cmdname" | awk '{print $1 }'
Pidof "parameter name"
Pgrep "cmdname"
The three running results in bash and busybox ash are slightly different,
The first method is identical, but the performance is not good because the number of invocati
This thing, if do not often operate, sincerely after a period of time forget clean. To master proficiency, it is necessary to practice more, there is nothing to say. Cool shell Nets Two articles good ha:Sed:Http://coolshell.cn/articles/9104.htmlAwk:Http://coolshell.cn/articles/9070.htmlMU class network Video materials:The regular expression of shell programming: http://www.imooc.com/learn/378Novice study, it is recommended to practice and repeatedly read the information.A simple example of
Directory:First, the operation Principle of shell programSecond, Shell common skills1. Command history2. Command aliases3. Command Reference4. File name Wildcard5. Common shortcut keys6. Complement function7. Input and output redirection and piping8. Interact with user commands9. Script specification establishment and execution10.bash Common Options11. Command Status ResultsContinue to be found in ...Three, the common knowledge points description1. Variables1) Variable type2) Local Variables3) E
AwkAwk is a programming language that has a strong ability to handle document data. AWK specializes in formatting messages from or from a large textExtract data from this document.AWK's command format is:awk [-F Filed-separator] "commands" input-file (s)awk divides a line of text by the delimiter (filed-separator) into multiple fields, which are then recorded as $1,$ 2 ... $ n. $Represents all domain values
starting with the N1 character from the right.Example:Variable= ' http://www. your domain name. com/cut-string.html 'Echo ${variable:0:4}Result: httpEcho ${variable:7}Result: www. your domain name. com/cut-string.htmlEcho ${variable:0-15:10}Results: cut-stringEcho ${variable:0-15}Results: cut-string.htmlThe third type:With other shell commands, such as cutThere are several main options for the Cut command:echo $variable | Cut-c1-4Result: httpecho $variable | cut-c8-Result: www. your domain name
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.