Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explain awk command

Tags:

unix

awk

Today I was searching for a command online to print next two lines after a pattern and I came across an awk command which I'm unable to understand.

$ /usr/xpg4/bin/awk '_&&_--;/PATTERN/{_=2}' input

Can someone explain it?

like image 548
CBR Avatar asked Aug 23 '13 16:08

CBR


People also ask

What is awk '{ print $3 }'?

txt. If you notice awk 'print $1' prints first word of each line. If you use $3, it will print 3rd word of each line.

How do you write awk command in Unix?

OPTIONS. Use FS for the input field separator (the value of the 'FS' predefined variable). Read the awk program source from the file PROGRAM-FILE, instead of from the first command line argument. The 'f' flag sets the maximum number of fields, and the 'r' flag sets the maximum record size.

What does awk mean in Unix?

AWK (awk) is a domain-specific language designed for text processing and typically used as a data extraction and reporting tool. Like sed and grep, it is a filter, and is a standard feature of most Unix-like operating systems.


1 Answers

See https://stackoverflow.com/a/17914105/1745001 for the answer that was duplicated here.

like image 161
Ed Morton Avatar answered Oct 14 '22 05:10

Ed Morton