Giter VIP home page Giter VIP logo

awk's Introduction

Introduction

The basic operation of Awk is to scan a sequence of input lines, from any number of files, one after another, searching for lines that are matched by any of the patterns in the program. The precise meaning of “match” depends on the pattern in ques

awk '$3 == 0 { print $1 }' file1 file2
$ awk '$3 == 0 { print $1 }'

awk -f progfile  optional list of input files
awk '{ print }' emp.data is same as awk '{ print $0 }' emp.data

Awk counts the number of fields in the current input line and stores the count in a built-in variable called NF alt text

NF, the Number of Fields

awk '{ print NF, $1, $NF }' emp.data # wNF, the Number of Fields

awk '{ print NR,  NF, $1, $NF }' emp.data  # prints the number of fields and the first and last fields of each input line.

awk '{ print "total pay of emp is", $1, "is", $2 * $3 }' emp.data  # Putting Text in the Output

awk -f first.awk emp.data 
awk '{ printf("Total Pay of %s is %f\n"), $1, $3 }' emp.data  

awk '{ printf("Total Pay of %s is %.2f\n"), $1, $3 }' emp.data 

awk '{ printf("Total Pay of %-8s is %.2f\n", $1, $2 * $3) }' emp.data

awk '{ printf("Total Pay of %-8s is %6.2f\n", $1, $2 * $3) }' emp.data 

awk '{ printf("Total Pay of %-8s is %6.2f\n", $1, $2 * $3) }' emp.data | sort -r # Sorting

Selection

$1 == "Susie"
$2 >= 20 
$2 * $3 > 200 
$2 >= 20 || $3 >= 20
$2 >= 20 && $3 >= 20
$2 >= 20 ! $3 >= 20
!($2 < 20 && $3 < 20)

Data Validation

awk's People

Contributors

pivot-useraccess avatar

Watchers

shananighans_arya avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.