'and' to prevent shell interpretation. The standard format of this Program Statement segment is:
'Pattern{ action }'
The pattern parameter can be any of the regular expressions of egrep. It can be made up of the syntax/RE/and some style matching techniques. Similar to SED, you can also use "," to separate the two formulas to select a certain range. For details about the matching, refer to the appendix. If you still don't understand it, find a Unix bo
'} '/etc/passwd//list user name with ID number greater than 500 awk Syntax rulesif (an expression)ActionElseActionAn if (expression) action; Else actionEg:Interpretation SDA4 capacity is less than 20MB alarm, otherwise display OKdf-h | grep "SDA4" | awk ' {if ($4while (condition)ActionSyntax format:X=1while (iPrint $i}egawk ' I=1 {} BEGIN {while (iDoActionwhile
Sed and AWK getting started. Sed and AWK are text processing artifacts in * nix command lines, which are quite powerful. they are all row-oriented, or they process text in one row after another, read the content from the standard input or file, execute the script command in one row, and then print...
Sed and awk are * powerful text processing artifacts in Nix command lines. they are all row-oriented, or they process text in one row and one row. They read content from standard input or files and execute script commands in one row, then print the output to the standard output until the end of the file (EOF ).
Sed
Sed
Sed and AWK getting started. Sed and AWK are text processing artifacts in * nix command lines, which are quite powerful. they are all row-oriented, or they process text in one row and one row. They read content from standard input or files and execute script commands in one row, then print the output to the standard ou
-----------------------------Overview-----------------------------------
The
Linux Text Processing tool (the following are commands and tools, and only as a display, not as a modification action)
grep (filtering, but does not support regular expressions)Egrep (regular expression support)Sed (row filter)awk (column filtering)
-
the conce
Sed tool Introduction
After learning about some basic applications of formal notation, what about it? Haha ~ You can play with two things, that is, sed and awk! These two guys are quite useful! For example, the logfile. Sh written by laruence analyzes the small programs in the login file, and uses and counts most of the analysis keywords. These two baby eggs are
grep or Egrep or awk filters two or more keywords | using grep to match "and" or "or" mode 2011-06-23 14:06
grep or Egrep or awk filters two or more keywords:Grep-e ' 123|abc ' filename/find the line containing 123 or ABC in the file (filename)Egrep ' 123|abc ' f
Sed awk tools and some common shell scripts
(1) sed
Sed is a streamlined and non-interactive stream editor. It enters the edit command in the command line and specifies the file name, and then displays the output on the screen.
The file content read row by row is stored in the temporary buffer, which is called the pat
maintained under '/dev/disk' # See man pages fstab (5), findfs (8), mount (8) and/or blkid (8) for more info # tmpfs/dev/shm tmpfs ults 0 0 devpts/dev/pts devptsgid = 5, mode = 6200 0 sysfs/syssysfs defaults 0 0 0 proc/procprocdefaults 0 0
③ Echo a path to sed and retrieve its directory name Through sed; for example, echo "/etc/sysconfig/" | sed, return/etcecho
] ruby] # sed-n '/ruby/p ' ab | Sed ' s/ruby//g ' #删除rubyInsert[[email protected] ruby] # sed-i ' $a bye ' ab #在文件ab中最后一行直接输入 "Bye"[email protected] ruby]# Cat ABHello!Ruby is me,welcome to my blog.EndByeDelete a matching rowSed-i '/Match string/d ' filename (note: If the match string is a variable, you need "" instead of ". Remember as if it were)Replace a strin
, default is space key[[email protected] ~]# cat 1a2a3a4a5ab2b3b4b5bc2c3c4c5c[[email protected] ~]# cat 1|awk ' {print $ \ t line: "NR" \ t the row total field: " NF} ' a line: 1 The total field of the row: 5b row: 2 The total field of the row: 5c row: 3 The Total field of the row: 5 Check the row of data that is less than 10 passwd the third column, and list only the account number and the third column. Cat/etc/passwd|
) Capitalize the first lowercase letter of each word[[Email protected] sed]# sed ' s/\b[a-z]/\u/g ' test.txt3.sed the last number in a row of a file[email protected] sed]# cat Test.txtErtFff**[ABCFD]123324444[Rty]**Fgfgf[[Email protected] sed]#
Tags: awkHttp://www.cnblogs.com/ginvip/p/6352157.htmlThis is a blog I found, the content of awk is written very well, need to seeawk about! No.(1) Take odd lines[[email protected] shell]# SEQ 10 | awk ' I=!i '13579(2) Take even lines[[email protected] shell]# SEQ 10 | awk '! (i=!i) '246810(3) SEQ 10 not after 4 lines[[email protected] shell]# SEQ 10 | Head-n-4123
/wyfs02/m02/73/49/wkiom1x5isgbnd98aacvjrggyge101.jpg "/>8.R command:the R command is a read command. SED uses this command to add the contents of a text file to a specific location in the current file. 650) this.width=650; "style=" Float:none; "title=" 27.png "alt=" wkiom1x5isgiiyizaafqdelvwzc614.jpg "src="/HTTP/ S3.51cto.com/wyfs02/m02/73/49/wkiom1x5isgiiyizaafqdelvwzc614.jpg "/>Some special commands for 9.sed
to er, that is, lovablelover.
The characters X {m}, X {M,}, and X {m, n} repeat: m times, at least m times, at least m times, not more than N timesO {5, 10} matches 5 ~ 10 o strings
| OrEcho "Tom and Jerry" | sed-r's/(Tom) and (Jerry)/\ 2 and \ 1 /'Echo "Tom G1, G2, G3 Jerry" | cut-d ""-F2Echo "ABC Def" | sed-r's/([A-Z] +) ([A-Z] +)/\ 2 \ 1 /'Echo "ABC Def" | sed
input the numbers:" Read aread bif (($a = = $b)), then echo "a = B" elif (($a > $b)) and then E Cho "a > B" Else echo "A (2) Find Files#!/bin/bashecho "Enter a file name:" Read AIF [-e/home/tach/$a];then echo "The file is exist!" else echo "The file is not exist!" Fi(3) Delete files of size 0#!/bin/bashfor filename in ' ls ' does a=$ (ls-l $filename | awk ' {print $} ') if (a==0), then rm $filename F Id
word and replaces it with [], result: [This] [was] [an] [example]echo this was digit 7 in a number | Sed '/digit \ ([0-9]\)/\l/' #参数 \1 (number 1) converts digit 7 to 7---------------------------------------------------------------Text=helloecho Hello World | Sed "s/$text/hello/" #输出结果HELLO World---------------------------------------------------------------Text clutter and return to normal (replace space,
Sed command
Sed only edits the copy of the original file in the buffer and does not change the source file. Therefore, to save the file, you must redirect it to another file.
Sed:
1. Sed [Option] 'sed command 'input file
2. Sed [O
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.