Awk practical tips

Source: Internet
Author: User

Awk 'nf'

Filter blank rows

Awk '! A [$0] ++'

Filter duplicate rows

Awk 'nf-= 2'

Filter out the last two columns

Awk 'a =! A'

Print odd rows

Awk '! (A =! A )'

Print even rows

Awk 'end {print Nr }'

Simulate WC-l

Awk 'in in {print "'\''"}'

Print single quotes. The quotation marks are followed by single quotes, and single quotes.

Awk 'in in {print "\""}'

Double quotation marks are printed, followed by double quotation marks.

Awk 'in in {rs = ""; FS = "\ n"} {print NF }'

Calculates the number of lines of each text segment based on an empty behavior.

Awk-VRS = "\ n"-vofs = "" '$1 = $1'

Based on the segmentation standard of each text segment of an empty behavior, a text segment is integrated into one line.

Awk '{A = $2; $2 = $4; $4 = A} 1'

Column exchange

Awk '/[^! -~] /'

Print rows containing Chinese Characters

Awk '/[! -~] /'

This will not be explained at the meeting. It is best to execute lang = C before executing this column.

Awk 'nf {A = $ NF} end {print }'

Print the last word in the last line

Awk '{print $1> "file"}' file

Only keep the first column of the file (Dangerous to directly modify the file content)

This article from the "lisp O & M path" blog, please be sure to keep this source

Awk practical tips

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: 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.