AWK resolution, awk resolution

Source: Internet
Author: User

AWK resolution, awk resolution
Cut command limitations

Df-h | cut-d ""-f 5/etc/passwd

 

The cut command cannot correctly intercept the content with spaces as the separator.


AWK format

Awk 'condition 1 {Action 1} condition 2 {Action 2 }... 'Filename'

 

Condition (Pattern) [relational expressions are generally used as conditions]:

X> 10 determine whether variable x is greater than 10

X> = 10 is greater than or equal

X <= 10 is less than or equal

 

Action ):

Formatted output: printf, print [\ n will be automatically added]

Process control statement: if/

 

 

Percentage of truncated/partitioned data

Df-h | grep sda2 | awk '{print $5}' | cut-d %-f1

 


BEGIN

Awk 'in in {printf "This is a test Script \ n"} {print $2 "\ t" $5} 'student.txt # first run the command followed by BEGIN

 

Awk 'in in {FS = ":"} {print $1 "\ t" $3} '/etc/passwd # display the specified separator

 

Awk-F: '{print $1 "\ t" $3}'/etc/passwd # Same as before

 


END

Cat/etc/passwd | grep/bin/bash | awk-F: 'End {print "The END... "} {print $1" \ t "$3} '# print the END Content Before the command ends.

 


Relational operators

Cat student.txt | grep-v NAME | awk '$3> = 80 {print $2 }'

Awk '$3> = 80 {print $2}' student.txt | grep-v NAME # An error may occur.


How to Use awk to analyze trace files

Not for the awk file, but for your. tr file, you need to write the awk code first, gawk-f loss. question added: it is the analysis of CBR data of WPAN. the TRACE file format is as follows: s 11.002432000

How to Use AWK to analyze tr files

The problem is too general. Please provide the tr file format and what do you want to analyze?

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.