Linux awk usage tutorial, linuxawk usage tutorial

Source: Internet
Author: User

Linux awk usage tutorial, linuxawk usage tutorial

How to Use awk in linux

AWK is an excellent text processing tool. The name is derived from the first letter of its founder Alfred Aho, Peter Weinberger, and Brian Kernighan. AWK provides extremely powerful features: supports style loading, flow control, mathematical operators, process control statements, and even built-in variables and functions. It has almost all the exquisite features of a complete language. In fact, AWK does have its own language: AWK programming language. The three creators have formally defined it as "style scanning and processing language ". It allows you to create short programs that read input files, Sort data, process data, perform calculations on input, and generate reports. There are countless other functions. Compared with grep search and sed editing, awk is particularly powerful in data analysis and report generation. To put it simply, awk refers to reading files row by row. Each line is sliced with spaces as the default separator, and the cut part is analyzed and processed. Printf '% s \ n' cat abc.txt 'printf' % s \ n' $ (cat abc.txt) printf' output type output format' output content output type: % s output string % I output integer % f output Floating Point Output Format: \ n newline \ t tab example: printf "%-5 s %-10 s %-4s \ n" NO Name Markprintf "%-5 s %-10 s %-4.2f \ n" 01 Tom 90.3456 printf "% -5 s %-10 s %-4.2f \ n "02 Jack 89.2345 printf" %-5 s %-10 s %-4.2f \ n "03 Jeff 98.4323 description: %-5 s is a string in the left-aligned format and the width is 5 (-indicates the left-aligned). If this parameter is not used, it is aligned again. %-4.2f format: the left-aligned width is 4, retain two decimal places. Printf '% s \ n'a B c d e fprintf' % 5 s % s \ n'a B c d e fprintf' %-5 s % s % s \ n' a B c d e f Fill cut is not powerful enough df-h | cut-d'-f 2df-h | awk '{print $2}' awk command Format: awk 'pattern1 {action1} pattern2 {action2 }... 'filenameawk default Delimiter is space or tab cat/etc/passwd | awk-F': ''{print $0} 'awk-F ': ''{print $2} '/etc/passwdawk-F ': ''1> 5 {print $1} 2> 1 {print $2} '/etc/passwdawk' BEGIN {print "this file is/etc/passwd"} {print $ 0} 'awk-F ': ''in in {print "this file is/etc/passwd"} {print $1} '/etc/passwdawk' {FS = ": "} {print $1} '/etc/passwdawk' BEGIN {FS = ": "} {print $1} '/etc/passwdawk' END {print" end of file "} {print $1} '/etc/passwd

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.