and returns the value of the updated *v
Atomic_dec_return (v): Subtract the value of *v by 1 and return the value of the updated *v
Atomic_add_return (i, V): Adds the value of *v to I and returns the value of the updated *v
Atomic_sub_return (i, v): Subtract the value of *v by I and return the value of the updated *v
There are also some atomic operations acting on bitmask:
Test_bit (NR, addr): Returns the
, atomic_t *v)//V increases the value I and returns True when the result is negativeint Atomic_add_return (int i, atomic_t *v)//V increases the value I and returns the resultint Atomic_sub_return (int i, atomic_t *v)//V reduces the value of I and returns the resultThe value of int atomic_inc_return (atomic_t *v)//V plus 1, and returns the resultThe value of int atomic_dec_return (atomic_t *v)//V is reduced by 1 and the result is returnedThe value of int atomic_dec_and_test (atomic_t *v)//V is mi
(1) awk principleThe principle of awk is to process the data in a file line by row, find content that matches what is given on the command line, and then program the next step if a match is found. If no match is found, continue with the next line.(2) Awk combatSed-n '/jd.com/p ' jfedu.txt awk '/jd.com/' jfedu.txtComments:AWK has the same lookup function as SED, unlike when awk does not need to add a P parameterSed-n '/jd.com/,/baidu.com/p ' jfedu.txt awk '/jd.com/,/baidu.com/' jfedu.txtawk ' {pr
From some sites to see the novel often appear in the spam ads, in anger write a crawler, the novel Link crawl down to save to TXT, with requests_html all done, code is simple, easy to get started.In the middle of the biggest problem is the coding problem, the first crawl down the content of the novel to keep the TXT garbled, the second URL coding problem, the third UnicodeencodeerrorFirst paste the source code, the back of the idea and the problems encountered detailed description. fromRequests_
Suppose the Apache log format is:
118.78.199.98–-[09/jan/2010:00:59:59 +0800] "Get/public/css/index.css http/1.1″304–" http://www.a.cn/common/ index.php "
" mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; GTB6.3) "
Issue 1: Find the most visited 10 IP in Apachelog.
awk ' {print $} ' apache_log |sort |uniq-c|sort-nr|head-n 10awk first grabs the IP from each log, such as the log format is customized, and the-F defines the separato
Awk processes multiple files
Awk processes multiple files one by one.
Demo1
$ cat $ cat 1.txt a 1 b 2c 3d 4$ cat 2.txt b 5 c 6d 7e 8$ awk ‘{print $0}‘ 1.txt 2.txta 1 b 2c 3d 4b 5 c 6d 7e 8
So how can we tell which file is being processed? Let's take a look at the built-in variables of awk.
Filename: Name of the file currently enteredFNR: Number of records of the current input fileNR: Total number of records that awk starts to processNF: Number of fields in the current recordFS: Input field del
the begin statement block;2. read a row from a file or stdin, and then execute statements2. Repeat this process until all the files are read;3. execute the end statement block;
Print current row
• When print without parameters is used, the current row is printed;Copy codeThe code is as follows: echo-e "line1 \ nline2" | awk 'In in {print "start" }{ print} END {print "End "}'• When print is separated by commas (,), the parameters are bounded by spaces;
Copy codeThe code is as follows:Echo | awk
ordinal that distinguishes commands.The value in the "read-write zone" in the command code may be _ioc_none (0 value) indicating no data transfer, _ioc_read (read), _ioc_write (write), _ioc_read|_ioc_write (bidirectional).The kernel defines the 4 macros _io (), _ior (), IOW (), and _IOWR () to assist in generating the above cmd. The following analysis of the implementation of _io (), other similar.
You can see the definition of _io () in asm-generic/ioctl.h :
#define _IO (
{statements }'
Work Mode1. Execute the begin statement block;2. Read a row from a file or stdin, and then execute statements2. repeat this process until all the files are read;3. Execute the end statement block;
Print current row
When the print without parameters is used, the current row is printed; echo -e "line1\nline2" | awk 'BEGIN{print "start"} {print } END{ print "End" }'
When print is separated by commas (,), the parameters are bounded by spaces;echo | awk ' {var1 = "v1" ; var2 = "V
(), _ior (), IOW (), and _IOWR () to assist in generating the above cmd. The following is an analysis of the implementation of _io (), other similar:in the asm-generic/ioctl.h can see in _io () Definition of :#define _IO (TYPE,NR) _ioc (_ioc_none, (Type), (NR), 0)Look again _IOC () Definition of :#define _IOC (dir,type,nr,size) \((dir) ((type) ((
(), _ior (), IOW (), and _IOWR () to assist in generating the above cmd. The following is an analysis of the implementation of _io (), other similar:You can see the definition of _io () in asm-generic/ioctl.h :#define _IO (TYPE,NR) _ioc (_ioc_none, (Type), (NR), 0)then look at the definition of _IOC () :#define _IOC (dir,type,nr,size) \((dir) ((type) ((
-increment, decrement, and subtract (without adding) to test whether it is 0, 0 returns true, otherwise Falseint atomic_inc_and_test (atomic_t *v) is returned; Int atomic _dec_and_test (atomic_t *v); int atomic_sub_and_test (int i, atomic_t *v); Operation and return: Add/subtract and increment/decrement the atomic variable, and return the new value int Atomic_add_return (int i, atomic_t *v); int Atomic_sub_return (int i, atomic_t *v); int Atomic_inc_return (atomic_t *v); int Atomic_dec_return (
, and return a new valueintAtomic_add_return (intI, atomic_t *v);intAtomic_sub_return (intI, atomic_t *v);intAtomic_inc_return (atomic_t *v);intAtomic_dec_return (atomic_t *v); Bit atomic operation://Set bitvoidSet_bit (NR,void*ADDR);//set the NR bit of the addr address, write 1//Clear BitsvoidClear_bit (NR,void*ADDR);//clear the addr address of the
(no addition) Tests whether it is 0, 0 returns True, otherwise returns Falseintatomic_inc_and_test (ATOMIC_TNBSP;*V); Intatomic_dec_and_test (atomic_ TNBSP;*V); Intatomic_sub_and_test (INTNBSP;I,NBSP;ATOMIC_TNBSP;*V);// operation and return: to the atomic variable to add/ Subtract and increment/decrement operations, and return a new value Intatomic_add_return (INTNBSP;I,NBSP;ATOMIC_TNBSP;*V); Intatomic_sub_return (int NBSP;I,NBSP;ATOMIC_TNBSP;*V); Intatomic_inc_return (atomic_t*v); Intatomic_de
awk command:1.Print line number and content:awk ' {print NR ': ' $ A} '2.Output: Even lines and odd lines to fileawk ' {print $0.txt > nr%2.txt} ' File3.Print surprisingly few lines of content: (three equivalent)awk ' nr%2==1 ' fileawk ' nr%2 ' all_file.txtawk ' i=!i ' filePrint out the contents of even rows: (three eq
Documents are as follows
# cat Cesca,1a,2b,3b,4c,2d,5
You need to get the number of ABCD occurrences, followed by the numbers and the average.
With Shell:
# grep-e ^a Cesc |awk-f ', ' {sum+=$2} end {print ' A, Count: ' NR ' sum: ' Sum ' Average: ' Sum/nr} 'A, count:2 sum:3 average:1.5# grep-e ^b Cesc |awk-f ', ' {sum+=$2} end {print ' B, Count: ' NR ' sum: '
1th. Where is awk? 1.1 awk built-in variables
fs
input field (column) delimiter /td>
-F:
equivalent to-VFS: /td>
nr
Number of R Ecord line number (record number)
nf
Number of filed columns per row
OFS TD valign= "Top" width= "567" >
Output output delimiter
rs
Record separator records delimiter each end tag is carria
the files are read;3. execute the end statement block;
Print current row
When the print without parameters is used, the current row is printed;
echo -e "line1\nline2" | awk 'BEGIN{print "start"} {print } END{ print "End" }'
When print is separated by commas (,), the parameters are bounded by spaces;
echo | awk ' {var1 = "v1" ; var2 = "V2"; var3="v3"; \print var1, var2 , var3; }'___FCKpd___43gt;v1 V2 v3
Use-concatenation operator ("" As concatenation operator );
echo | awk ' {var1 = "v1" ; va
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.