The Linux op Korimasa is an expression of awk

Source: Internet
Author: User
Tags posix

One: The Linux op korimasa the sed of the expression

Awk is an excellent text processing tool, one of the most powerful data processing engines available in Linux and UNIX environments.

1. Options | parameters:

-F FS or--field-separator FS
Specifies the input file delimiter, FS is a string, or is a regular expression, such as-f:.
-V Var=value or--asign var=value
Assigns a user-defined variable.
-F scripfile or--file ScriptFile
Reads the awk command from the script file.
-MF nnn AND-MR nnn
Set intrinsic limits on the NNN value, the-MF option limits the maximum number of blocks assigned to NNN, and the-MR option limits the maximum number of records. These two features are the extended functionality of the Bell Lab version of AWK and are not available in standard awk.
-W compact or--compat,?-W Traditional or--traditional
Run awk in compatibility mode. So Gawk's behavior is exactly the same as the standard awk, and all awk extensions are ignored.
-W copyleft or--copyleft,?-W copyright or--copyright
Print a brief copyright message.
-W Help or--help,?-W usage or--usage
Print all awk options and a short description of each option.
-W Lint or--lint
Print warnings for structures that cannot be ported to traditional UNIX platforms.
-W lint-old or--lint-old
Print a warning about a structure that cannot be ported to a traditional UNIX platform.
-W POSIX
Turn on compatibility mode. However, the following limitations are not recognized: \x, function keyword, func, swap sequence, and when FS is a space, the new row is used as a domain delimiter, and the operators * * and **= are not valid in lieu of ^ and ^=;fflush.
-W re-interval or--re-inerval
Allows the use of interval regular expressions, reference (POSIX character class in grep), such as parenthesis expression [[: Alpha:]].
-W source Program-text or--source Program-text
Use Program-text as the source code, which can be mixed with the-f command.
-W version or--version
Print the version of the bug report information.

Two. Example exercises:

-F defines the field delimiter
[[email protected] ~]# awk-f: ' {print $1,$4} ' test.txt take first and four splits per line
[[email protected] ~]# awk-f: ' {print $1,$4} ' test.txt go to the last paragraph
NR line number
[Email protected] ~]#
[Email protected] ~]# awk-f: ' nr<=2 | | Nr>=7{print NR, "------", $ ' test.txt

[Email protected] ~]# awk-f: '/nologin$/{print $ ' test.txt #打印以nologin结尾行的第一个字段

[[email protected] ~]# awk-f: ' $1~/^r.*t$/{print nr,$3} ' test.txt print the first field starts with R and ends with T
[[email protected] ~]# awk-f: ' $1== ' root ' {print nr,$3} ' test.txt match first field root

[[email protected] ~]# awk-f: ' $ >= 7{print nr,$1} ' test.txt print a field with a UID greater than or equal to 7
[Email protected] ~]#
[Email protected] ~]# count=7
[[email protected] ~]# awk-v x= $count-F: ' $ $ >= x{print nr,$1} ' test.txt Custom #一个conut变量可以更改conut = Several, the printed result also changes

[Email protected] ~]# Ifconfig | awk ' Nr==2{print ' #取IP地址

[Email protected] ~]# ip_addr= ' ifconfig | awk ' Nr==2{print '
[Email protected] ~]# echo $ip _addr #保存ip地址

[email protected] ~]# cat a.txt |sort |uniq #查看并去重
[email protected] ~]# cat a.txt |sort |uniq-c #查看去重数


[email protected] ~]# cat test.txt |cut-d:-f1,3 view first and third parts

[[email protected] ~]# du-sh/etc View directory Size
36m/etc

[[email protected] ~]# Find/-type F file type
[[email protected] ~]# find/name "*.txt" Find all files ending in. txt
[[email protected] ~]# Find/-size +30m Find/Lower files larger than 30M
[[email protected] ~]# Find/-size-30m-size +10m greater than 10M less than 30M
[[email protected] ~]# Find/-size +2m-type f-name \*.txt

The Linux op Korimasa is an expression of awk

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.