Frontier Software

awk

Manual

print

#!/usr/bin/bash

awk '{ print }' $*

BEGIN

#!/usr/bin/bash

awk 'BEGIN { print "NAME\tRATE\tHOURS"; print "" }
    { print }' $*

END

#!/usr/bin/bash

awk ' { OFS="\t" }
BEGIN { print "NAME", "RATE", "HOURS"; print "" }
    { print $1, $2, $3}
    { rate = rate + $2 }
    { hours = hours + $3 }
END { print "AVERAGE", rate / NR, hours / NR }' $*
#!/usr/bin/bash

ExampleGroup 'basic awk oneliner'

  Example 'print emp.data'
    When call bin/eg1.sh bin/emp.data
    The output should eq 'Beth	4.00	0
Dan	3.75	0
Kathy	4.00	10
Mark	5.00	20
Mary	5.50	22
Susie	4.25	18'
  End

  Example 'print a header using BEGIN'
    When call bin/eg2.sh bin/emp.data
    The output should eq 'NAME	RATE	HOURS

Beth	4.00	0
Dan	3.75	0
Kathy	4.00	10
Mark	5.00	20
Mary	5.50	22
Susie	4.25	18'
  End

  Example 'print average rates and hours using END'
    When call bin/eg3.sh bin/emp.data
    The output should eq 'NAME RATE HOURS

Beth	4.00	0
Dan	3.75	0
Kathy	4.00	10
Mark	5.00	20
Mary	5.50	22
Susie	4.25	18
AVERAGE	4.41667	11.6667'
  End

End

Built-in variables

ARGC
number of command-line arguments
ARGV[n]
array of command-line arguments
FILENAME
name of current input file
FNR
input record number in current file
FS
input field separator (default blank)
NF
number of fields in current input record
NR
input record number since beginning
OFMT
output format for numbers (default "%.6g")
OFS
output field separator (default blank)
ORS
output record separator (default newline)
RLENGTH
length of string matched by regular expression in match
RS
input record separator (default newline)
RSTART
beginning position of string matched by match
SUBSEP
separator for array subscripts of form [i,j...] (default "\034")