SlideShare ist ein Scribd-Unternehmen logo
1 von 11
Downloaden Sie, um offline zu lesen
Programming for Evolutionary Biology
        March 17th - April 1st 2012
            Leipzig, Germany




Introduction to Unix systems
    Extra: awk and gawk
        Giovanni Marco Dall'Olio
        Universitat Pompeu Fabra
            Barcelona (Spain)
awk
   “awk” is a “swiss army” command line tool to 
      manipulate tabular files
   Things you can do with awk:
          Extract all the lines of a file that match a pattern, and 
            print only some of the columns (instead of “grep | 
            cut”)
          Add a prefix/suffix to all the element of a column 
            (instead of “cut | paste”)
          Sum values of different columsn
awk and gawk
   In these slides we will be talking about awk
   In reality, the original awk is not available 
      anymore. We will use gawk, a free version of 
      gawk developed by the GNU project
Basic awk usage
   “awk '<pattern to select lines> {instructions to be 
      executed on each line}' ” 
Example awk usage
   “awk '$0 ~ AAC {print}' sample_vcf.vcf”
          $0 ~ AAC → select all the lines that contain AAC
          {print} → for each line that matches the previous 
             expression, print it
Column names in awk
   awk assumes that you are working on tabular files
   Each column of the file can be accessed by 
     $<column­name>. For example, $2 is the second 
     column of the file
   $0 matches all the columns of the file
Accessing columns in awk
   “awk '{print $1, $2, $3}' sample_vcf.vcf” → prints 
      the first three columns
   “awk '{print $0}' sample_vcf.vcf” → print all the 
      columns
Adding a prefix to a column
         with awk
   A common awk usage is to add a prefix or suffix to 
     all the entries of a column
   Example: 
          awk '{print $2 “my_prefix”$2}' myfile.txt
Summing columns in awk
   If two columns contain numeric values, we can use 
       awk to sum them
   Usage:
          “awk '{print $1 + $2}' myfile.txt
Selecting columns with awk
   Awk can be used to select columns, 
   It is like grep, but more powerful, because it let you 
       specify on which columns the match must be
   This example will print all the lines that have a 
     AAC in their first colum:
          “awk '$1 ~ AAC {print}' myfile.txt 
More on awk
   awk is a complete programming language
   It is the equivalent of a spreadsheet for the 
       command line
   If you want to know more, check the book “Gawk 
       effective AWK Programming” at 
       http://www.gnu.org/software/gawk/manual

Weitere ähnliche Inhalte

Was ist angesagt?

Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
Raghu nath
 
Talk Unix Shell Script 1
Talk Unix Shell Script 1Talk Unix Shell Script 1
Talk Unix Shell Script 1
Dr.Ravi
 
Airlover 20030324 1
Airlover 20030324 1Airlover 20030324 1
Airlover 20030324 1
Dr.Ravi
 
Bash shell
Bash shellBash shell
Bash shell
xylas121
 
Talk Unix Shell Script
Talk Unix Shell ScriptTalk Unix Shell Script
Talk Unix Shell Script
Dr.Ravi
 
Unix Basics
Unix BasicsUnix Basics
Unix Basics
Dr.Ravi
 
Unix And C
Unix And CUnix And C
Unix And C
Dr.Ravi
 

Was ist angesagt? (20)

Pipes and filters
Pipes and filtersPipes and filters
Pipes and filters
 
Linux shell scripting
Linux shell scriptingLinux shell scripting
Linux shell scripting
 
Linux intro 5 extra: makefiles
Linux intro 5 extra: makefilesLinux intro 5 extra: makefiles
Linux intro 5 extra: makefiles
 
Unix shell scripts
Unix shell scriptsUnix shell scripts
Unix shell scripts
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
Unix Tutorial
Unix TutorialUnix Tutorial
Unix Tutorial
 
Talk Unix Shell Script 1
Talk Unix Shell Script 1Talk Unix Shell Script 1
Talk Unix Shell Script 1
 
Shellscripting
ShellscriptingShellscripting
Shellscripting
 
Airlover 20030324 1
Airlover 20030324 1Airlover 20030324 1
Airlover 20030324 1
 
Unix
UnixUnix
Unix
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
Bash shell
Bash shellBash shell
Bash shell
 
Talk Unix Shell Script
Talk Unix Shell ScriptTalk Unix Shell Script
Talk Unix Shell Script
 
Unix Basics
Unix BasicsUnix Basics
Unix Basics
 
Basics of shell programming
Basics of shell programmingBasics of shell programming
Basics of shell programming
 
Course 102: Lecture 4: Using Wild Cards
Course 102: Lecture 4: Using Wild CardsCourse 102: Lecture 4: Using Wild Cards
Course 102: Lecture 4: Using Wild Cards
 
Course 102: Lecture 7: Simple Utilities
Course 102: Lecture 7: Simple Utilities Course 102: Lecture 7: Simple Utilities
Course 102: Lecture 7: Simple Utilities
 
Unix And C
Unix And CUnix And C
Unix And C
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Chap06
Chap06Chap06
Chap06
 

Andere mochten auch

Andere mochten auch (20)

Linux intro 2 basic terminal
Linux intro 2   basic terminalLinux intro 2   basic terminal
Linux intro 2 basic terminal
 
Linux intro 1 definitions
Linux intro 1  definitionsLinux intro 1  definitions
Linux intro 1 definitions
 
Unix Operating System
Unix Operating SystemUnix Operating System
Unix Operating System
 
Awk Introduction
Awk IntroductionAwk Introduction
Awk Introduction
 
Sed Introduction
Sed IntroductionSed Introduction
Sed Introduction
 
WildFly Avançado - TDC Floripa 2015
WildFly Avançado - TDC Floripa 2015WildFly Avançado - TDC Floripa 2015
WildFly Avançado - TDC Floripa 2015
 
Intro to linux performance analysis
Intro to linux performance analysisIntro to linux performance analysis
Intro to linux performance analysis
 
Samsung mobile root
Samsung mobile rootSamsung mobile root
Samsung mobile root
 
Machine Learning and Hadoop: Present and Future
Machine Learning and Hadoop: Present and FutureMachine Learning and Hadoop: Present and Future
Machine Learning and Hadoop: Present and Future
 
History of L0phtCrack
History of L0phtCrackHistory of L0phtCrack
History of L0phtCrack
 
Nigerian design and digital marketing agency
Nigerian design and digital marketing agencyNigerian design and digital marketing agency
Nigerian design and digital marketing agency
 
VideoLan VLC Player App Artifact Report
VideoLan VLC Player App Artifact ReportVideoLan VLC Player App Artifact Report
VideoLan VLC Player App Artifact Report
 
JBUG Brasil - Desvendando as features do WildFly.
JBUG Brasil - Desvendando as features do WildFly.JBUG Brasil - Desvendando as features do WildFly.
JBUG Brasil - Desvendando as features do WildFly.
 
脆弱性診断って何をどうすればいいの?(おかわり)
脆弱性診断って何をどうすればいいの?(おかわり)脆弱性診断って何をどうすればいいの?(おかわり)
脆弱性診断って何をどうすればいいの?(おかわり)
 
Open Source Security Testing Methodology Manual - OSSTMM by Falgun Rathod
Open Source Security Testing Methodology Manual - OSSTMM by Falgun RathodOpen Source Security Testing Methodology Manual - OSSTMM by Falgun Rathod
Open Source Security Testing Methodology Manual - OSSTMM by Falgun Rathod
 
Dangerous google dorks
Dangerous google dorksDangerous google dorks
Dangerous google dorks
 
How to Setup A Pen test Lab and How to Play CTF
How to Setup A Pen test Lab and How to Play CTF How to Setup A Pen test Lab and How to Play CTF
How to Setup A Pen test Lab and How to Play CTF
 
Thesis defence of Dall'Olio Giovanni Marco. Applications of network theory to...
Thesis defence of Dall'Olio Giovanni Marco. Applications of network theory to...Thesis defence of Dall'Olio Giovanni Marco. Applications of network theory to...
Thesis defence of Dall'Olio Giovanni Marco. Applications of network theory to...
 
Nmap not only a port scanner by ravi rajput comexpo security awareness meet
Nmap not only a port scanner by ravi rajput comexpo security awareness meet Nmap not only a port scanner by ravi rajput comexpo security awareness meet
Nmap not only a port scanner by ravi rajput comexpo security awareness meet
 
Hacking in shadows By - Raghav Bisht
Hacking in shadows By - Raghav BishtHacking in shadows By - Raghav Bisht
Hacking in shadows By - Raghav Bisht
 

Ähnlich wie Linux intro 5 extra: awk

import java.io.BufferedReader;import java.io.BufferedWriter;.docx
import java.io.BufferedReader;import java.io.BufferedWriter;.docximport java.io.BufferedReader;import java.io.BufferedWriter;.docx
import java.io.BufferedReader;import java.io.BufferedWriter;.docx
wilcockiris
 
DevChatt 2010 - *nix Cmd Line Kung Foo
DevChatt 2010 - *nix Cmd Line Kung FooDevChatt 2010 - *nix Cmd Line Kung Foo
DevChatt 2010 - *nix Cmd Line Kung Foo
brian_dailey
 
Introduction To Python
Introduction To  PythonIntroduction To  Python
Introduction To Python
shailaja30
 

Ähnlich wie Linux intro 5 extra: awk (20)

awk_intro.ppt
awk_intro.pptawk_intro.ppt
awk_intro.ppt
 
Unix day4 v1.3
Unix day4 v1.3Unix day4 v1.3
Unix day4 v1.3
 
stack.ppt
stack.pptstack.ppt
stack.ppt
 
Unix interview questions
Unix interview questionsUnix interview questions
Unix interview questions
 
Love Your Command Line
Love Your Command LineLove Your Command Line
Love Your Command Line
 
Gráficas en python
Gráficas en python Gráficas en python
Gráficas en python
 
Unix - Class7 - awk
Unix - Class7 - awkUnix - Class7 - awk
Unix - Class7 - awk
 
import java.io.BufferedReader;import java.io.BufferedWriter;.docx
import java.io.BufferedReader;import java.io.BufferedWriter;.docximport java.io.BufferedReader;import java.io.BufferedWriter;.docx
import java.io.BufferedReader;import java.io.BufferedWriter;.docx
 
DevChatt 2010 - *nix Cmd Line Kung Foo
DevChatt 2010 - *nix Cmd Line Kung FooDevChatt 2010 - *nix Cmd Line Kung Foo
DevChatt 2010 - *nix Cmd Line Kung Foo
 
Csv file read and write
Csv file read and writeCsv file read and write
Csv file read and write
 
Introduction to r studio on aws 2020 05_06
Introduction to r studio on aws 2020 05_06Introduction to r studio on aws 2020 05_06
Introduction to r studio on aws 2020 05_06
 
Awk primer and Bioawk
Awk primer and BioawkAwk primer and Bioawk
Awk primer and Bioawk
 
Python1
Python1Python1
Python1
 
Awk-An Advanced Filter
Awk-An Advanced FilterAwk-An Advanced Filter
Awk-An Advanced Filter
 
The Ring programming language version 1.8 book - Part 94 of 202
The Ring programming language version 1.8 book - Part 94 of 202The Ring programming language version 1.8 book - Part 94 of 202
The Ring programming language version 1.8 book - Part 94 of 202
 
Introduction To Python
Introduction To  PythonIntroduction To  Python
Introduction To Python
 
Ch05
Ch05Ch05
Ch05
 
intro unix/linux 06
intro unix/linux 06intro unix/linux 06
intro unix/linux 06
 
Linux
LinuxLinux
Linux
 
Linux
LinuxLinux
Linux
 

Mehr von Giovanni Marco Dall'Olio

The true story behind the annotation of a pathway
The true story behind the annotation of a pathwayThe true story behind the annotation of a pathway
The true story behind the annotation of a pathway
Giovanni Marco Dall'Olio
 
(draft) perl e bioinformatica - presentazione per ipw2008
(draft) perl e bioinformatica - presentazione per ipw2008(draft) perl e bioinformatica - presentazione per ipw2008
(draft) perl e bioinformatica - presentazione per ipw2008
Giovanni Marco Dall'Olio
 

Mehr von Giovanni Marco Dall'Olio (18)

Fehrman Nat Gen 2014 - Journal Club
Fehrman Nat Gen 2014 - Journal ClubFehrman Nat Gen 2014 - Journal Club
Fehrman Nat Gen 2014 - Journal Club
 
Agile bioinf
Agile bioinfAgile bioinf
Agile bioinf
 
Version control
Version controlVersion control
Version control
 
Wagner chapter 5
Wagner chapter 5Wagner chapter 5
Wagner chapter 5
 
Wagner chapter 4
Wagner chapter 4Wagner chapter 4
Wagner chapter 4
 
Wagner chapter 3
Wagner chapter 3Wagner chapter 3
Wagner chapter 3
 
Wagner chapter 2
Wagner chapter 2Wagner chapter 2
Wagner chapter 2
 
Wagner chapter 1
Wagner chapter 1Wagner chapter 1
Wagner chapter 1
 
Hg for bioinformatics, second part
Hg for bioinformatics, second partHg for bioinformatics, second part
Hg for bioinformatics, second part
 
Hg version control bioinformaticians
Hg version control bioinformaticiansHg version control bioinformaticians
Hg version control bioinformaticians
 
The true story behind the annotation of a pathway
The true story behind the annotation of a pathwayThe true story behind the annotation of a pathway
The true story behind the annotation of a pathway
 
Plotting data with python and pylab
Plotting data with python and pylabPlotting data with python and pylab
Plotting data with python and pylab
 
Pycon
PyconPycon
Pycon
 
Makefiles Bioinfo
Makefiles BioinfoMakefiles Bioinfo
Makefiles Bioinfo
 
biopython, doctest and makefiles
biopython, doctest and makefilesbiopython, doctest and makefiles
biopython, doctest and makefiles
 
Web 2.0 e ricerca scientifica - Web 2.0 and scientific research
Web 2.0 e ricerca scientifica - Web 2.0 and scientific researchWeb 2.0 e ricerca scientifica - Web 2.0 and scientific research
Web 2.0 e ricerca scientifica - Web 2.0 and scientific research
 
Perl Bioinfo
Perl BioinfoPerl Bioinfo
Perl Bioinfo
 
(draft) perl e bioinformatica - presentazione per ipw2008
(draft) perl e bioinformatica - presentazione per ipw2008(draft) perl e bioinformatica - presentazione per ipw2008
(draft) perl e bioinformatica - presentazione per ipw2008
 

Kürzlich hochgeladen

Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 

Kürzlich hochgeladen (20)

SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
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
 
Connecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAKConnecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAK
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
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
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
 
The UX of Automation by AJ King, Senior UX Researcher, Ocado
The UX of Automation by AJ King, Senior UX Researcher, OcadoThe UX of Automation by AJ King, Senior UX Researcher, Ocado
The UX of Automation by AJ King, Senior UX Researcher, Ocado
 
Top 10 Symfony Development Companies 2024
Top 10 Symfony Development Companies 2024Top 10 Symfony Development Companies 2024
Top 10 Symfony Development Companies 2024
 

Linux intro 5 extra: awk

  • 1. Programming for Evolutionary Biology March 17th - April 1st 2012 Leipzig, Germany Introduction to Unix systems Extra: awk and gawk Giovanni Marco Dall'Olio Universitat Pompeu Fabra Barcelona (Spain)
  • 2. awk  “awk” is a “swiss army” command line tool to  manipulate tabular files  Things you can do with awk:  Extract all the lines of a file that match a pattern, and  print only some of the columns (instead of “grep |  cut”)  Add a prefix/suffix to all the element of a column  (instead of “cut | paste”)  Sum values of different columsn
  • 3. awk and gawk  In these slides we will be talking about awk  In reality, the original awk is not available  anymore. We will use gawk, a free version of  gawk developed by the GNU project
  • 4. Basic awk usage  “awk '<pattern to select lines> {instructions to be  executed on each line}' ” 
  • 5. Example awk usage  “awk '$0 ~ AAC {print}' sample_vcf.vcf”  $0 ~ AAC → select all the lines that contain AAC  {print} → for each line that matches the previous  expression, print it
  • 6. Column names in awk  awk assumes that you are working on tabular files  Each column of the file can be accessed by  $<column­name>. For example, $2 is the second  column of the file  $0 matches all the columns of the file
  • 7. Accessing columns in awk  “awk '{print $1, $2, $3}' sample_vcf.vcf” → prints  the first three columns  “awk '{print $0}' sample_vcf.vcf” → print all the  columns
  • 8. Adding a prefix to a column with awk  A common awk usage is to add a prefix or suffix to  all the entries of a column  Example:   awk '{print $2 “my_prefix”$2}' myfile.txt
  • 9. Summing columns in awk  If two columns contain numeric values, we can use  awk to sum them  Usage:  “awk '{print $1 + $2}' myfile.txt
  • 10. Selecting columns with awk  Awk can be used to select columns,   It is like grep, but more powerful, because it let you  specify on which columns the match must be  This example will print all the lines that have a  AAC in their first colum:  “awk '$1 ~ AAC {print}' myfile.txt 
  • 11. More on awk  awk is a complete programming language  It is the equivalent of a spreadsheet for the  command line  If you want to know more, check the book “Gawk  effective AWK Programming” at  http://www.gnu.org/software/gawk/manual