SlideShare a Scribd company logo
1 of 21
Download to read offline
Learn AWK
in 15 minutes
Maxime Besson
info@worteks.com
2
(vɔʁ.tɛks)
Services
Heterogeneous and complex
infrastructures, cloud, mail,
authentication, security

Studies, audit and consulting

Technical expertise

Technical support

Training

R&D
Edition
Collaboration and
application portal
Mutualized platform
for development
Identity and Access
Management
Partnership
Why learn AWK in $(date +%Y)?
•
It’s everywhere:
# Yes, everywhere:
$ docker run -it --rm alpine awk 'END{print "Hello"}' /dev/null
Hello
•
It’s powerful and versatile
•
It plays nicely with many other command line tools
•
This:
– https://adamdrake.com/command-line-tools-can-be-235x-
faster-than-your-hadoop-cluster.html
What I'm going to teach you
awk -F: '($3<1000){s++} END{print s}'
•
Don't worry, it looks scarier than it really is !
•
If you understand what this does, you can sleep until
the next talk !
Structure of an AWK command
awk [program arguments] code [input file]
•
Program arguments change how the interpreter works
•
Code is an awk script, usually quote-protected
•
Input file is optional, awk will then read the standard
input
•
Awk writes to standard output
•
You can put the script in a file if it gets too big for a one-
liner
What AWK does (pseudo-code)
foreach line
if (CONDITION) then
ACTIONS
endif
if (CONDITION) then
ACTIONS
endif
…
endfor
What you write (real AWK code)
CONDITION {
ACTIONS
}
CONDITION {
ACTIONS
}
What you write (one-liner)
awk ‘CONDITION {ACTIONS} CONDITION {ACTIONS}’
AWK conditions
•
if CONDITION empty, INSTRUCTIONS are applied to
every line
•
BEGIN / END : will be run only once
•
/regexp/
•
( expression ) : usually a test for equality
•
some others...
•
Any logical combination of the above
AWK variables
•
AWK allows you to set any variable you like
•
AWK defines some variables for you:
– NR : current „record” (line) number
– NF : how many „fields” the record has
– $0 : the current line
– $1, $2, … : n-th field on the line
Fields are delimited by tabs and spaces by default, this can
be overriden with the -F option
•
AWK is great at handling CSV files !
That's all...
•
Now you know (almost) all the theory. The rest is in man
pages
Examples
awk '{print NR}'
Examples
awk '{print NR}'
awk '{print NR, $0}'
Examples
awk '{print NR}'
awk '{print NF}'
awk 'END {print NR}'
Examples
awk '{print NR}'
awk '{print NF}'
awk 'END {print NR}'
awk ' /root/ { print $0 }'
Examples
awk -F: ' /root/ { print $3 }' /etc/passwd
Examples
awk -F: ' /root/ { print $3 }' /etc/passwd
awk -F: ' ($3==1000) { print $1 }' /etc/passwd
Examples
awk -F: ' /root/ { print $3 }' /etc/passwd
awk -F: ' ($3==1000) { print $1 }' /etc/passwd
awk -F: ' ($1==”root”) { print $6 }' /etc/passwd
Examples
awk -F: ' /root/ { print $3 }' /etc/passwd
awk -F: ' ($3==1000) { print $1 }' /etc/passwd
awk -F: ' ($1==”root”) { print $6 }' /etc/passwd
awk -F: '($6 ~ "^/home"){ c++ } END{print c}'
Conclusion
•
When should I use awk
– Shell one liners
– One shot processing of CSV data
●
'($2 == something) {sum = sum+ $3}'
●
group-by using arrays
•
When should I not use awk
– Internationalization
– Complex calculations
– Complex data structures
– Long scripts in general
22
Thanks for your
attention
More informations:
info@worteks.com
@worteks_com
linkedin.com/company/worteks

More Related Content

Similar to #OSSPARIS19 - Learn AWK in 15 minutes - MAXIME BESSON, Worteks

Itb session v_memcached
Itb session v_memcachedItb session v_memcached
Itb session v_memcached
Skills Matter
 
Drupal Camp Brighton 2015: Ansible Drupal Medicine show
Drupal Camp Brighton 2015: Ansible Drupal Medicine showDrupal Camp Brighton 2015: Ansible Drupal Medicine show
Drupal Camp Brighton 2015: Ansible Drupal Medicine show
George Boobyer
 
Stack kicker devopsdays-london-2013
Stack kicker devopsdays-london-2013Stack kicker devopsdays-london-2013
Stack kicker devopsdays-london-2013
Simon McCartney
 
Sparkling Water 5 28-14
Sparkling Water 5 28-14Sparkling Water 5 28-14
Sparkling Water 5 28-14
Sri Ambati
 
Interface de Voz con Rails
Interface de Voz con RailsInterface de Voz con Rails
Interface de Voz con Rails
Svet Ivantchev
 
The Art Of Readable Code
The Art Of Readable CodeThe Art Of Readable Code
The Art Of Readable Code
Baidu, Inc.
 
Shell Scripts
Shell ScriptsShell Scripts
Shell Scripts
Dr.Ravi
 

Similar to #OSSPARIS19 - Learn AWK in 15 minutes - MAXIME BESSON, Worteks (20)

Itb session v_memcached
Itb session v_memcachedItb session v_memcached
Itb session v_memcached
 
NYPHP March 2009 Presentation
NYPHP March 2009 PresentationNYPHP March 2009 Presentation
NYPHP March 2009 Presentation
 
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine Yard
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine YardHow I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine Yard
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine Yard
 
An Introduction to Windows PowerShell
An Introduction to Windows PowerShellAn Introduction to Windows PowerShell
An Introduction to Windows PowerShell
 
RHCSA EX200 - Summary
RHCSA EX200 - SummaryRHCSA EX200 - Summary
RHCSA EX200 - Summary
 
Quick trip around the Cosmos - Things every astronaut supposed to know
Quick trip around the Cosmos - Things every astronaut supposed to knowQuick trip around the Cosmos - Things every astronaut supposed to know
Quick trip around the Cosmos - Things every astronaut supposed to know
 
Docker Security workshop slides
Docker Security workshop slidesDocker Security workshop slides
Docker Security workshop slides
 
Terraform in deployment pipeline
Terraform in deployment pipelineTerraform in deployment pipeline
Terraform in deployment pipeline
 
Perly Parallel Processing of Fixed Width Data Records
Perly Parallel Processing of Fixed Width Data RecordsPerly Parallel Processing of Fixed Width Data Records
Perly Parallel Processing of Fixed Width Data Records
 
Running Docker clusters on AWS (November 2016)
Running Docker clusters on AWS (November 2016)Running Docker clusters on AWS (November 2016)
Running Docker clusters on AWS (November 2016)
 
Juggling Chainsaws: Perl and MongoDB
Juggling Chainsaws: Perl and MongoDBJuggling Chainsaws: Perl and MongoDB
Juggling Chainsaws: Perl and MongoDB
 
#PDR15 - waf, wscript and Your Pebble App
#PDR15 - waf, wscript and Your Pebble App#PDR15 - waf, wscript and Your Pebble App
#PDR15 - waf, wscript and Your Pebble App
 
Paexec — distributes tasks over network or CPUs
Paexec — distributes tasks over network or CPUsPaexec — distributes tasks over network or CPUs
Paexec — distributes tasks over network or CPUs
 
Aprovisionamiento multi-proveedor con Terraform - Plain Concepts DevOps day
Aprovisionamiento multi-proveedor con Terraform  - Plain Concepts DevOps dayAprovisionamiento multi-proveedor con Terraform  - Plain Concepts DevOps day
Aprovisionamiento multi-proveedor con Terraform - Plain Concepts DevOps day
 
Drupal Camp Brighton 2015: Ansible Drupal Medicine show
Drupal Camp Brighton 2015: Ansible Drupal Medicine showDrupal Camp Brighton 2015: Ansible Drupal Medicine show
Drupal Camp Brighton 2015: Ansible Drupal Medicine show
 
Stack kicker devopsdays-london-2013
Stack kicker devopsdays-london-2013Stack kicker devopsdays-london-2013
Stack kicker devopsdays-london-2013
 
Sparkling Water 5 28-14
Sparkling Water 5 28-14Sparkling Water 5 28-14
Sparkling Water 5 28-14
 
Interface de Voz con Rails
Interface de Voz con RailsInterface de Voz con Rails
Interface de Voz con Rails
 
The Art Of Readable Code
The Art Of Readable CodeThe Art Of Readable Code
The Art Of Readable Code
 
Shell Scripts
Shell ScriptsShell Scripts
Shell Scripts
 

More from Paris Open Source Summit

#OSSPARIS19 : Comment ONLYOFFICE aide à organiser les travaux de recherches ...
#OSSPARIS19 : Comment ONLYOFFICE aide à organiser les travaux de recherches  ...#OSSPARIS19 : Comment ONLYOFFICE aide à organiser les travaux de recherches  ...
#OSSPARIS19 : Comment ONLYOFFICE aide à organiser les travaux de recherches ...
Paris Open Source Summit
 
#OSSPARIS19 - Comment financer un projet de logiciel libre - LUDOVIC DUBOST, ...
#OSSPARIS19 - Comment financer un projet de logiciel libre - LUDOVIC DUBOST, ...#OSSPARIS19 - Comment financer un projet de logiciel libre - LUDOVIC DUBOST, ...
#OSSPARIS19 - Comment financer un projet de logiciel libre - LUDOVIC DUBOST, ...
Paris Open Source Summit
 

More from Paris Open Source Summit (20)

#OSSPARIS19 : Control your Embedded Linux remotely by using WebSockets - Gian...
#OSSPARIS19 : Control your Embedded Linux remotely by using WebSockets - Gian...#OSSPARIS19 : Control your Embedded Linux remotely by using WebSockets - Gian...
#OSSPARIS19 : Control your Embedded Linux remotely by using WebSockets - Gian...
 
#OSSPARIS19 : A virtual machine approach for microcontroller programming : th...
#OSSPARIS19 : A virtual machine approach for microcontroller programming : th...#OSSPARIS19 : A virtual machine approach for microcontroller programming : th...
#OSSPARIS19 : A virtual machine approach for microcontroller programming : th...
 
#OSSPARIS19 : RIOT: towards open source, secure DevOps on microcontroller-bas...
#OSSPARIS19 : RIOT: towards open source, secure DevOps on microcontroller-bas...#OSSPARIS19 : RIOT: towards open source, secure DevOps on microcontroller-bas...
#OSSPARIS19 : RIOT: towards open source, secure DevOps on microcontroller-bas...
 
#OSSPARIS19 : The evolving (IoT) security landscape - Gianluca Varisco, Arduino
#OSSPARIS19 : The evolving (IoT) security landscape - Gianluca Varisco, Arduino#OSSPARIS19 : The evolving (IoT) security landscape - Gianluca Varisco, Arduino
#OSSPARIS19 : The evolving (IoT) security landscape - Gianluca Varisco, Arduino
 
#OSSPARIS19: Construire des applications IoT "secure-by-design" - Thomas Gaza...
#OSSPARIS19: Construire des applications IoT "secure-by-design" - Thomas Gaza...#OSSPARIS19: Construire des applications IoT "secure-by-design" - Thomas Gaza...
#OSSPARIS19: Construire des applications IoT "secure-by-design" - Thomas Gaza...
 
#OSSPARIS19 : Detecter des anomalies de séries temporelles à la volée avec Wa...
#OSSPARIS19 : Detecter des anomalies de séries temporelles à la volée avec Wa...#OSSPARIS19 : Detecter des anomalies de séries temporelles à la volée avec Wa...
#OSSPARIS19 : Detecter des anomalies de séries temporelles à la volée avec Wa...
 
#OSSPARIS19 : Supervision d'objets connectés industriels - Eric DOANE, Zabbix
#OSSPARIS19 : Supervision d'objets connectés industriels - Eric DOANE, Zabbix#OSSPARIS19 : Supervision d'objets connectés industriels - Eric DOANE, Zabbix
#OSSPARIS19 : Supervision d'objets connectés industriels - Eric DOANE, Zabbix
 
#OSSPARIS19: Introduction to scikit-learn - Olivier Grisel, Inria
#OSSPARIS19: Introduction to scikit-learn - Olivier Grisel, Inria#OSSPARIS19: Introduction to scikit-learn - Olivier Grisel, Inria
#OSSPARIS19: Introduction to scikit-learn - Olivier Grisel, Inria
 
#OSSPARIS19 - Fostering disruptive innovation in AI with JEDI - André Loesekr...
#OSSPARIS19 - Fostering disruptive innovation in AI with JEDI - André Loesekr...#OSSPARIS19 - Fostering disruptive innovation in AI with JEDI - André Loesekr...
#OSSPARIS19 - Fostering disruptive innovation in AI with JEDI - André Loesekr...
 
#OSSPARIS19 : Comment ONLYOFFICE aide à organiser les travaux de recherches ...
#OSSPARIS19 : Comment ONLYOFFICE aide à organiser les travaux de recherches  ...#OSSPARIS19 : Comment ONLYOFFICE aide à organiser les travaux de recherches  ...
#OSSPARIS19 : Comment ONLYOFFICE aide à organiser les travaux de recherches ...
 
#OSSPARIS19 : MDPH : une solution collaborative open source pour l'instructio...
#OSSPARIS19 : MDPH : une solution collaborative open source pour l'instructio...#OSSPARIS19 : MDPH : une solution collaborative open source pour l'instructio...
#OSSPARIS19 : MDPH : une solution collaborative open source pour l'instructio...
 
#OSSPARIS19 - Understanding Open Source Governance - Gilles Gravier, Wipro Li...
#OSSPARIS19 - Understanding Open Source Governance - Gilles Gravier, Wipro Li...#OSSPARIS19 - Understanding Open Source Governance - Gilles Gravier, Wipro Li...
#OSSPARIS19 - Understanding Open Source Governance - Gilles Gravier, Wipro Li...
 
#OSSPARIS19 : Publier du code Open Source dans une banque : Mission impossibl...
#OSSPARIS19 : Publier du code Open Source dans une banque : Mission impossibl...#OSSPARIS19 : Publier du code Open Source dans une banque : Mission impossibl...
#OSSPARIS19 : Publier du code Open Source dans une banque : Mission impossibl...
 
#OSSPARIS19 : Libre à vous ! Raconter les libertés informatiques à la radio -...
#OSSPARIS19 : Libre à vous ! Raconter les libertés informatiques à la radio -...#OSSPARIS19 : Libre à vous ! Raconter les libertés informatiques à la radio -...
#OSSPARIS19 : Libre à vous ! Raconter les libertés informatiques à la radio -...
 
#OSSPARIS19 - Le logiciel libre : un enjeu politique et social - Etienne Gonn...
#OSSPARIS19 - Le logiciel libre : un enjeu politique et social - Etienne Gonn...#OSSPARIS19 - Le logiciel libre : un enjeu politique et social - Etienne Gonn...
#OSSPARIS19 - Le logiciel libre : un enjeu politique et social - Etienne Gonn...
 
#OSSPARIS19 - Conflits d’intérêt & concurrence : la place de l’éditeur dans l...
#OSSPARIS19 - Conflits d’intérêt & concurrence : la place de l’éditeur dans l...#OSSPARIS19 - Conflits d’intérêt & concurrence : la place de l’éditeur dans l...
#OSSPARIS19 - Conflits d’intérêt & concurrence : la place de l’éditeur dans l...
 
#OSSPARIS19 - Table ronde : souveraineté des données
#OSSPARIS19 - Table ronde : souveraineté des données #OSSPARIS19 - Table ronde : souveraineté des données
#OSSPARIS19 - Table ronde : souveraineté des données
 
#OSSPARIS19 - Comment financer un projet de logiciel libre - LUDOVIC DUBOST, ...
#OSSPARIS19 - Comment financer un projet de logiciel libre - LUDOVIC DUBOST, ...#OSSPARIS19 - Comment financer un projet de logiciel libre - LUDOVIC DUBOST, ...
#OSSPARIS19 - Comment financer un projet de logiciel libre - LUDOVIC DUBOST, ...
 
#OSSPARIS19 - BlueMind v4 : les dessous technologiques de 10 ans de travail p...
#OSSPARIS19 - BlueMind v4 : les dessous technologiques de 10 ans de travail p...#OSSPARIS19 - BlueMind v4 : les dessous technologiques de 10 ans de travail p...
#OSSPARIS19 - BlueMind v4 : les dessous technologiques de 10 ans de travail p...
 
#OSSPARIS19 - Tuto de première installation de VITAM, un système d'archivage ...
#OSSPARIS19 - Tuto de première installation de VITAM, un système d'archivage ...#OSSPARIS19 - Tuto de première installation de VITAM, un système d'archivage ...
#OSSPARIS19 - Tuto de première installation de VITAM, un système d'archivage ...
 

Recently uploaded

Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
FIDO Alliance
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
panagenda
 
CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)
Wonjun Hwang
 

Recently uploaded (20)

Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 
Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - Questionnaire
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptx
 
Generative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfGenerative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdf
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development Companies
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
UiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewUiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overview
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate Guide
 
CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)
 
How to Check GPS Location with a Live Tracker in Pakistan
How to Check GPS Location with a Live Tracker in PakistanHow to Check GPS Location with a Live Tracker in Pakistan
How to Check GPS Location with a Live Tracker in Pakistan
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptx
 
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
 

#OSSPARIS19 - Learn AWK in 15 minutes - MAXIME BESSON, Worteks

  • 1. Learn AWK in 15 minutes Maxime Besson info@worteks.com
  • 2. 2 (vɔʁ.tɛks) Services Heterogeneous and complex infrastructures, cloud, mail, authentication, security  Studies, audit and consulting  Technical expertise  Technical support  Training  R&D Edition Collaboration and application portal Mutualized platform for development Identity and Access Management Partnership
  • 3. Why learn AWK in $(date +%Y)? • It’s everywhere: # Yes, everywhere: $ docker run -it --rm alpine awk 'END{print "Hello"}' /dev/null Hello • It’s powerful and versatile • It plays nicely with many other command line tools • This: – https://adamdrake.com/command-line-tools-can-be-235x- faster-than-your-hadoop-cluster.html
  • 4. What I'm going to teach you awk -F: '($3<1000){s++} END{print s}' • Don't worry, it looks scarier than it really is ! • If you understand what this does, you can sleep until the next talk !
  • 5. Structure of an AWK command awk [program arguments] code [input file] • Program arguments change how the interpreter works • Code is an awk script, usually quote-protected • Input file is optional, awk will then read the standard input • Awk writes to standard output • You can put the script in a file if it gets too big for a one- liner
  • 6. What AWK does (pseudo-code) foreach line if (CONDITION) then ACTIONS endif if (CONDITION) then ACTIONS endif … endfor
  • 7. What you write (real AWK code) CONDITION { ACTIONS } CONDITION { ACTIONS }
  • 8. What you write (one-liner) awk ‘CONDITION {ACTIONS} CONDITION {ACTIONS}’
  • 9. AWK conditions • if CONDITION empty, INSTRUCTIONS are applied to every line • BEGIN / END : will be run only once • /regexp/ • ( expression ) : usually a test for equality • some others... • Any logical combination of the above
  • 10. AWK variables • AWK allows you to set any variable you like • AWK defines some variables for you: – NR : current „record” (line) number – NF : how many „fields” the record has – $0 : the current line – $1, $2, … : n-th field on the line Fields are delimited by tabs and spaces by default, this can be overriden with the -F option • AWK is great at handling CSV files !
  • 11. That's all... • Now you know (almost) all the theory. The rest is in man pages
  • 13. Examples awk '{print NR}' awk '{print NR, $0}'
  • 14. Examples awk '{print NR}' awk '{print NF}' awk 'END {print NR}'
  • 15. Examples awk '{print NR}' awk '{print NF}' awk 'END {print NR}' awk ' /root/ { print $0 }'
  • 16. Examples awk -F: ' /root/ { print $3 }' /etc/passwd
  • 17. Examples awk -F: ' /root/ { print $3 }' /etc/passwd awk -F: ' ($3==1000) { print $1 }' /etc/passwd
  • 18. Examples awk -F: ' /root/ { print $3 }' /etc/passwd awk -F: ' ($3==1000) { print $1 }' /etc/passwd awk -F: ' ($1==”root”) { print $6 }' /etc/passwd
  • 19. Examples awk -F: ' /root/ { print $3 }' /etc/passwd awk -F: ' ($3==1000) { print $1 }' /etc/passwd awk -F: ' ($1==”root”) { print $6 }' /etc/passwd awk -F: '($6 ~ "^/home"){ c++ } END{print c}'
  • 20. Conclusion • When should I use awk – Shell one liners – One shot processing of CSV data ● '($2 == something) {sum = sum+ $3}' ● group-by using arrays • When should I not use awk – Internationalization – Complex calculations – Complex data structures – Long scripts in general
  • 21. 22 Thanks for your attention More informations: info@worteks.com @worteks_com linkedin.com/company/worteks