SlideShare ist ein Scribd-Unternehmen logo
1 von 32
Downloaden Sie, um offline zu lesen
Unixkurs
Verarbeiten von Textdateien,
Umgang mit Pipes
Unix-Philosophie
• Klein ist schön.
• Jedes Programm soll genau eine Sache gut machen.
• Portabilität geht über Effizienz.
• Speichere Daten in Textdateien.
Unix Toolbox
• auf allen Unixen verfügbar
• Finden von Mustern
• Anzeigen von Dateien oder Teilen davon
• Extraktion von Informationen
• Zeilenweises Sortieren
• leicht zuVerknüpfen mit Pipes
cat
• Programm zum Ausgeben und
Zusammenfügen von Dateien
• Ausgeben:
• cat datei.txt
• Zusammenfügen:
• cat datei1.txt datei2.txt > beides.txt
cat
datei1.txt
datei2.txt
cat datei1.txt datei2.txt > datei3.txt
datei3.txt
cat
sort
• Programm zum zeilenweisen Sortieren von
Textdateien
• sortiert ohne weitere Optionen
• nach der Inhalt der ganzen Zeile
• lexikographisch (zB. "1, 11, 2, 223, 3")
• in aufsteigender Reihenfolge
split
datei.txt
split -l 20 datei.txt schnipsel-
split
schnipsel-aa
schnipsel-ab
schnipsel-ac
nach 20 Zeilen Präfix
split
• Programm zum Aufteilen von Dateien in
kleinere Teile
sort
erste
Spalte
numerisch
absteigende
Reihenfolge
sort -k2 -n -r tabelle.txt
168	Franz
173 	 Meike
153	Frieda
143	Adele
111	Karl
96	 Siegrid
202	Ulf
179	Hannes
133	Alfred
178	Verena
153	Bertram
111	Karl
133	Alfred
143	Adele
153	Bertram
153	Frieda
168	Franz
173 	 Meike
178	Verena
179	Hannes
202	Ulf
96	 Siegrid
sort
168	Franz
173 	 Meike
153	Frieda
143	Adele
111	Karl
96	 Siegrid
202	Ulf
179	Hannes
133	Alfred
178	Verena
153	Bertram
sort -n
96	 Siegrid
111	Karl
133	Alfred
143	Adele
153	Bertram
153	Frieda
168	Franz
173 	 Meike
178	Verena
179	Hannes
202	Ulf
168	Franz
173 	 Meike
153	Frieda
143	Adele
111	Karl
96	 Siegrid
202	Ulf
179	Hannes
133	Alfred
178	Verena
153	Bertram
sort -k2
143	Adele
133	Alfred
153	Bertram
168	Franz
153	Frieda
179	Hannes
111	Karl
173	Meike
96	 Siegrid
202	Ulf
178	Verena
168	Franz
173 	 Meike
153	Frieda
143	Adele
111	Karl
96	 Siegrid
202	Ulf
179	Hannes
133	Alfred
178	Verena
153	Bertram
sort -r -k2
178	Verena
202	Ulf
96	 Siegrid
173	Meike
111	Karl
179	Hannes
153	Frieda
168	Franz
153	Bertram
133	Alfred
143	Adele
grep
• findet Zeilen, in denen bestimmte Muster
vorkommen
• eines der praktischsten Kommandos in der
Unixwelt
• kommt auch mit "regulären Ausdrücken" klar
global/regular expression/print
grep f
168	Franz	
m
173	Meike	
f
153	Frieda	 f
143	Adele	
f
111	Karl	 m
96	 Siegrid	
f
202	Ulf	m
179	Hannes	 m
133	Alfred	 m
178	Verena	 f
153	Bertram	
m
173	Meike	
f
153	Frieda	 f
143	Adele	
f
96	 Siegrid	
f
202	Ulf	m
133	Alfred	 m
178	Verena	 f
grep f$
168	Franz	
m
173	Meike	
f
153	Frieda	 f
143	Adele	
f
111	Karl	 m
96	 Siegrid	
f
202	Ulf	m
179	Hannes	 m
133	Alfred	 m
178	Verena	 f
153	Bertram	
m
173	Meike	
f
153	Frieda	
143	Adele	
f
96	 Siegrid
178	Verena	
Zeilenende
Exkurs: reguläre Ausdrücke
Reguläre Ausdrücke sind Zeichenketten die
Mengen von Zeichenketten mit bestimmten
syntaktischen Regeln beschreiben.
John Kleen
(1909-1994)
Erfinder der regulären A
Exkurs: reguläre Ausdrücke
Ausdruck Bedeutung
. ein beliebiges Zeichen
a* beliebig viele a
.* beliebig viele beliebige Zeichen (alles)
[0-3] Zahl zwischen 0 und 3
f$ Zeilenende
^1 Zeilenanfang
Exkurs: reguläre Ausdrücke
• Wie beschreibt man die Menge
{Tanne,Tonne,Tenne,..}?
• Der zweite Buchstabe ist vorhanden aber
beliebig.
• Der passende reguläre Ausdruck wäre:
T.nne
Exkurs: reguläre Ausdrücke
• “Menge aller Sätze die mit Das beginnen,
und mit Ende aufhören."
• Der passende reguläre Ausdruck wäre:
^Das.*Ende$
grep e.*e
168	Franz	
m
173	Meike	
f
153	Frieda	 f
143	Adele	
f
111	Karl	 m
96	 Siegrid	
f
202	Ulf	m
179	Hannes	 m
133	Alfred	 m
178	Verena	 f
153	Bertram	
m
173	Meike	
f
143	Adele	
f
178	Verena	
beliebig viel
irgendwas
grep -v e.*e
168	Franz	
m
173	Meike	
f
153	Frieda	 f
143	Adele	
f
111	Karl	 m
96	 Siegrid	
f
202	Ulf	m
179	Hannes	 m
133	Alfred	 m
178	Verena	 f
153	Bertram	
m
168	Franz	
m
153	Frieda	
111	Karl	 m
96	 Siegrid
202	Ulf	m
179	Hannes	
133	Alfred	
153	Bertram
beliebig viel
irgendwas
Zeilen die Muster
nicht enthalten
head/tail
• Geben die letzen/ersten Zeilen in einer
Textdatei wieder
head -n 5
168	Franz	
m
173	Meike	
f
153	Frieda	 f
143	Adele	
f
111	Karl	 m
96	 Siegrid	
f
202	Ulf	m
179	Hannes	 m
133	Alfred	 m
178	Verena	 f
153	Bertram	
m
168	Franz	
m
173	Meike	
f
153	Frieda	 f
143	Adele	
f
111	Karl	 m
tail -n 5
168	Franz	
m
173	Meike	
f
153	Frieda	 f
143	Adele	
f
111	Karl	 m
96	 Siegrid	
f
202	Ulf	m
179	Hannes	 m
133	Alfred	 m
178	Verena	 f
153	Bertram	
m
202	Ulf	m
179	Hannes	 m
133	Alfred	 m
178	Verena	 f
153	Bertram	
m
Unix Pipes
• Erlauben das im Wesentlichen das
"Aneinanderschalten" von Programmen
• vergleichbar mit einem Filtersystem, in dem
Wasser mehrere Stationen durchlaufen
muss
Unix-Pipes
• Alle Programme haben drei Kanäle
Programm
Eingabe (0)
Ausgabe (1)
Fehler (2)
Unix-Pipes
• Die Kanäle werden über Pipes verbunden
who
Eingabe (0)
Fehler (2)
grep zx
Pipesyntax
• programm1 | programm2 | programm3
• programm > ausgabe
• programm < eingabe
• programm >> ausgabe
• programm 1> ausgabe 2> fehler
grep m$ tabelle.txt sort -n head -n 3
grep m$ tabelle.txt | sort -n | head -n 3
grep m$ tabelle.txt sort -n head -n 3
werden gleichzeitig gestartet und warten auf Eingaben
grep m$ tabelle.txt | sort -n | head -n 3
Daten fließen konstant

Weitere ähnliche Inhalte

Empfohlen

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Empfohlen (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Unixkurs 03 - Pipes