Awk control functions

Source: Internet
Author: User

Awk control functions

Example
 

$ Cat datafilenorthwest NW Joel Craig 3.0. 98 3 4 western WE Sharon Kelly 5.3. 97 5 23 southwest SW Chris Foster 2.7. 8 2 18 southern SO May Chin 5.1. 95 4 15 southeast SE Derek Johnson 4.0. 7 4 17 eastern EA Suan Beal 4.4. 84 5 20 northeast ne tj nickls 5.1. 94 3 13 north NO Val Shultz 4.5. 89 5 9 central CT Sheri Watson 5.7. 94 5 13 $ awk '{if ($5 >= 4.5) next; print $1} 'datafilenorthwestsouthwestsoutheasteasternnorth

Note: If the number of fields is greater than 5th, read the next line of the input file (datafile) and start from the starting point of the awk script (that is, the BEGIN block ). Otherwise, print the first field.

Example

$ Awk '{if ($2 ~ /S/) {print; exit 0} 'datafilesouthwest SW Chris Foster 2.7. 8 2 18 $ echo $? 0

Note: If the first field of the record contains the letter S, the record is printed and exited from the awk program. The exit state is saved in the variable $? .

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.