Professional Documents
Culture Documents
31/07/2006
+91.9911064207 12:58:46 PM
awk -- 11
awk
Copyright/Acknowledgements
12:58:47PM
12:58:47
12:58:47 PM
PM
info@ackabs.net +91.9911064207 11/04/2014
Module
Module -- 22
Introduction
31/07/2006
+91.9911064207 12:58:47 PM
awk -- 33
awk
History
1977: The original version of awk was written in at AT&T Bell Laboratories
1985: A new version introduced user-defined functions, multiple input
streams and computed expressions.
Generally became available with Unix System V Release 3.1
The awk version in System V Release 4.0 added some new features and also
cleaned up the language.
The specification for awk in the POSIX Command Language and Utilities
standard further clarified the language based on feedback from both the
gawk designers and the original Bell Labs awk designers
1986: The GNU gawk was written by Paul Rubin and Jay Fenlason with
advice from Richard Stallman. John Woods contributed parts of the code.
1988 and 1989: David Trueman and Arnold Robbins thoroughly reworked
gawk for compatibility with the newer awk.
31/07/2006
+91.9911064207 12:58:47 PM
awk -- 44
awk
Introduction
31/07/2006
+91.9911064207 12:58:47 PM
awk -- 55
awk
Versions
oawk (old AWK)
The first AWK version. It is still around on many UNIX systems. If
you have an oawk on your system, you probably have nawk, too.
Only required if you have older AWK scripts that require the older
AWK version.
nawk (new AWK)
Extension of OAWK. This is now the standard AWK version. Any
references made here to this version apply to the GNU AWK gawk
as well.
gawk (GNU AWK)
Similar to NAWK but entirely re-written from scratch and open
source.
awk
Generic or default name which is usually linked with nawk or
gawk.
awk is also available for different OS like DOS, Windows, etc.
31/07/2006
+91.9911064207 12:58:48 PM
awk -- 66
awk
Command Line
Name Phone Address City State Country
==============================================================
Vinamra 98212344 16,Sec 24 Noida UP India
Atanu 31087031 20B,Pkt C NewDelhi Delhi India
Abhi 29374563 RatHole NewDelhi Delhi India
Britney 32325723 HerHome City State USA
31/07/2006
+91.9911064207 12:58:48 PM
awk -- 77
awk
Command Line
equivalent to
$ awk '{ print $0 }' /etc/passwd
31/07/2006
+91.9911064207 12:58:48 PM
awk -- 88
awk
Command Line
Suppose /etc/passwd contains:
root:x:0:0:root:/root:/bin/bash
nfsnobody:x:65534:65534:AnonNFS
User:/var/lib/nfs:/sbin/nologin
atanu:x:0:0::/home/atanu:/bin/bash
rat:x:500:501::/home/rat:/bin/bash
test:x:501:502::/home/test:/bin/bash
Try
Try the
the above
above two
two awk
awk commands
commands and
and describe
describe what
what you
you observe.
observe.
31/07/2006
+91.9911064207 12:58:48 PM
awk -- 99
awk
Command Line
Now
Now try
try the
the above
above modified
modified commands
commands and
and describe
describe what
what you
you
observe.
observe.
31/07/2006
+91.9911064207 12:58:48 PM
awk -- 10
awk 10
$ awk -F":" '{ print $1 }' /etc/passwd
Explain
Explain What
What isis happening
happening above
above
31/07/2006
+91.9911064207 12:58:48 PM
awk -- 11
awk 11
Field Separator
Field Separator
Discuss
Discuss tabular
tabular data
data storage
storage
31/07/2006
+91.9911064207 12:58:48 PM
awk -- 12
awk 12
Command Line
awk -F":" '{ print "username: " $1 "\t\tuid:" $3" }' /etc/passwd
Try
Try the
the above
above variations
variations and
and explain
explain what
what isis happening
happening
31/07/2006
+91.9911064207 12:58:48 PM
awk -- 13
awk 13
Command Line
Suppose /etc/passwd contains:
root:x:0:0:root:/root:/bin/bash
nfsnobody:x:65534:65534:AnonNFS
User:/var/lib/nfs:/sbin/nologin
atanu:x:0:0::/home/atanu:/bin/bash
rat:x:500:501::/home/rat:/bin/bash
test:x:501:502::/home/test:/bin/bash
Try
Try the
the above
above three
three variations
variations and
and explain
explain what
what isis happening
happening
31/07/2006
+91.9911064207 12:58:48 PM
awk -- 14
awk 14
Patterns
ADV
/Smith / || /Jones /
31/07/2006
+91.9911064207 12:58:48 PM
awk -- 15
awk 15
Built In variables
ADV
31/07/2006
+91.9911064207 12:58:48 PM
awk -- 16
awk 16
Comparsions
== equal to
!= not equal to
> greater than
< less than
>= greater than or equal to
<= less than or equal to
31/07/2006
+91.9911064207 12:58:48 PM
awk -- 17
awk 17
References
https://www.gnu.org/software/gawk/manual/gawk.html
12:58:47PM
12:58:47
12:58:47 PM
PM
info@ackabs.net +91.9911064207 11/04/2014
Module
Module -- 18
18
Copyright/Acknowledgements
12:58:47PM
12:58:47
12:58:47 PM
PM
info@ackabs.net +91.9911064207 11/04/2014
Module
Module -- 19
19
Acknowledgements
12:58:47PM
12:58:47
12:58:47 PM
PM
info@ackabs.net +91.9911064207 11/04/2014
Module
Module -- 20
20
Versions
12:58:47PM
12:58:47
12:58:47 PM
PM
info@ackabs.net +91.9911064207 11/04/2014
Module
Module -- 21
21
That's all, folks!!
...till we meet again...
31/07/2006
+91.9911064207 12:58:48 PM
awk -- 22
awk 22