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?
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.
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.
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.
See https://stackoverflow.com/a/17914105/1745001 for the answer that was duplicated here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With