awk

awk linux command cheatsheet by Thamizhiniyan C S

Introduction

Awk is a scripting language used for manipulating data and generating reports.The awk command programming language requires no compiling, and allows the user to use variables, numeric functions, string functions, and logical operators.


Syntax

awk [flags] [select pattern/find(sort)/commands] [input file]

Program Structure

BEGIN Block

BEGIN {awk-commands}

BODY Block

/pattern/ {awk-commands}

END Block

END {awk-commands}

Important Flags


Built in Variables


printf statement

awk's printf statement is the same as that in C, except that the * format specifier is not supported.

SYNTAX: printf format, expr1, expr2, ..., exprn

awk printf conversion characters

printf examples


Examples

Last updated