SlideShare una empresa de Scribd logo
1 de 15
Descargar para leer sin conexión
Haskell-awk

Haskell text processor for the commandline
Mario Pastorelli
Introduction
awk
a generic text processor where
“A file is treated as a sequence of records, and by
default each line is a record.” - Alfred V. Aho
developed in 1977 by Alfred Aho, Peter Weinberger, and Brian
Kernighan @ Bell Labs
uses AWK as programming language
ak'EI {pit"el Wrd"}
w BGN
rn Hlo ol! '

procedural
interpreted
a program is a series of pattern action pairs
Why another awk?
“Whenever faced with a problem, some people say
`Lets use AWK.' Now, they have two problems.” - D.
Tilbrook
avoid the AWK programming language
use a generic language, not a DSL
BGNslt" bcca,)frii abai]1r";o( i brr ";rn r
EI{pi(a
"a;o( n )[[]=;="fri n )=" ipit }
nb$wrs" bcca
u
od a
"

procedural (imperative) vs functional programming for stream
processing
Haskell-awk (Hawk)
a generic text processor where
“A stream is treated as a sequence of records, and
by default each line is a record.”
the same philosophy of awk!
developed in 2013 by me and Samuel Gélineau, the name is a tribute
to awk
uses Haskell as programming language
hw 'HloWrd"
ak "el ol!'

functional
(incrementally) compiled
a program is a Haskell expression
Why Haskell
expressive, clean and concise
>fle od[,,,]
itr d 1234
[,]
13

functions as composable building blocks
>ltwrCut=sm.mp(egh.wrs .lns
e odon
u
a lnt
od)
ie
>:yewrCut
tp odon
wrCut: Srn - It
odon : tig > n
>wrCut" 23n 56n 89
odon 1
4
7
"
9

partial application
>:yemp
tp a
mp: ( - b - []- []
a : a > ) > a > b
>:yent
tp o
nt: Bo - Bo
o : ol > ol
>:yempnt
tp a o
mpnt: [ol - [ol
a o : Bo] > Bo]
>mpnt[reFle
a o Tu,as]
[as,re
FleTu]

point-free style, laziness ...
Hawk
Modes
evaluate an expression
$hw ''
ak 1
1
$hw '12'
ak [,]
1
2
$hw '[,][,]'
ak [12,34]'
12
34

apply an expression to the input
$eh '2n'|hw - '.ees'
co 1n3
ak a Lrvre
3
2
1

map an expression to each record of the input
$eh ' 2n 4 |hw - '.ees'
co 1 3 '
ak m Lrvre
21
43
IO format
The input is, by default, a list of list of strings where lines are
separated by n and words by spaces
$eh ' 2n 4 |hw - 'hw
co 1 3 '
ak a so'
["""",""""]
[1,2][3,4]

Options -d/-D are provided to change delimiters or set them to
empty
$eh ',;,'|hw - -''-'''hw
co 1234
ak a d, D; so'
["""",""""]
[1,2][3,4]
$eh ' 2n 4 |hw - -' 'hw
co 1 3 '
ak a d' so'
[12,34]
" "" "
$eh ' 2n 4 |hw - -' -' 'hw
co 1 3 '
ak a d' D' so'
" 2n 4n
1 3 "

The output can be any type that instantiate the typeclass Rows
cas(hwa = Rw awee
ls So ) > os
hr
rp : BtSrn - a- [yetig
er : yetig >
> BtSrn]
Examples
get all users of a UNIX system
$ct/t/asd|hw -:- '.ed
a ecpsw
ak d m Lha'
ro
ot
deo
amn
..
.

select username and userid
$ct/t/asd|hw -:-'t - 'l- ( ! 0l! 2'
a ecpsw
ak d o' m  > l ! , ! )
ro
ot
0
deo 1
amn
..
.

sort by username (instead of pid)
$ct/t/asd|hw -:- '.oty(opr `n Lha)
a ecpsw
ak d a LsrB cmae o` .ed'
bnx22bn/i:bns
i::::i:bn/i/h
deo::::amn/s/bn/i/h
amnx11deo:ursi:bns
..
.

get the number of users using each shell

>ct/t/asd|hw -d '.a (.ed&&Llnt).Lgop.Lsr .LmpLls'
a ecpsw
ak a: Lmp Lha & .egh
.ru
.ot
.a .at
/i/ah1
bnbs:
..
.
Context
Hawk can be customized using files inside the context directory (by
default ~/.hawk)
The most important file is prelude.hs that contains the "runtime
context"
$ct~.akpeueh
a /hw/rld.s
{#LNUG EtneDfutue,OelaeSrns#}
- AGAE xeddealRls vroddtig ipr Peue
mot rld
ipr qaiidDt.yetigLz.hr a B
mot ulfe aaBtSrn.ayCa8 s
ipr qaiidDt.ita L
mot ulfe aaLs s

for instance, we can add a function for taking elements in an
interval
$eh 'aeewe se=Ltk ( -s .Ldo s > ~.akpeueh
co tkBten
.ae e
)
.rp ' > /hw/rld.s
$sq010|hw - 'aeewe 24
e
0
ak a tkBten
'
2
3
Implementation
Hawk must be fast
cache the context
use the timestamp to check if the context is changed since last
run
compile it with ghc
use locks to compile only once when multiple Hawk instances
instances are running
hw '1.'|hw - '.ae3
ak [.]
ak a Ltk '

use ByteString instead of String
...
Parse and interpret Haskell
Hawk combines two Haskell libraries
haskell-src-exts to deal with haskell source code
>ipr Lnug.akl.xsPre
mot agaeHselEt.asr
>gtoPams"- LNUG NIpiiPeueOelaeSrns#}n
eTprga {# AGAE omlctrld,vroddtig -"
Prek[agaerga(rLc
asO LnugPam Sco
{rFlnm ="nnw.s,scie=1 scoun=1)
scieae
ukonh" rLn
, rClm
}
[dn "omlctrld"Iet"vroddtig"]
Iet NIpiiPeue,dn OelaeSrns]

hint to interpret the user expression
>ipr Lnug.akl.nepee
mot agaeHselItrrtr
>rnnepee $stmot [Dt.n" > itrrt""(s: It
uItrrtr
eIprs "aaIt] > nepe 1 a : n)
Rgt1
ih
>rnnepee $stmot [Dt.n" > itrrt"o"(s: It
uItrrtr
eIprs "aaIt] > nepe fo a : n)
Lf (otopl [hErr{rMg="o i soe `o'})
et WnCmie Gcro ers
Nt n cp: fo"]
Thank you!
https://github.com/gelisam/hawk

Más contenido relacionado

La actualidad más candente

COSCUP2012: How to write a bash script like the python?
COSCUP2012: How to write a bash script like the python?COSCUP2012: How to write a bash script like the python?
COSCUP2012: How to write a bash script like the python?Lloyd Huang
 
Bash shell
Bash shellBash shell
Bash shellxylas121
 
Shell programming 1.ppt
Shell programming  1.pptShell programming  1.ppt
Shell programming 1.pptKalkey
 
OpenGurukul : Language : Shell Scripting
OpenGurukul : Language : Shell ScriptingOpenGurukul : Language : Shell Scripting
OpenGurukul : Language : Shell ScriptingOpen Gurukul
 
Intro to Linux Shell Scripting
Intro to Linux Shell ScriptingIntro to Linux Shell Scripting
Intro to Linux Shell Scriptingvceder
 
BASH Guide Summary
BASH Guide SummaryBASH Guide Summary
BASH Guide SummaryOhgyun Ahn
 
Unix Commands
Unix CommandsUnix Commands
Unix CommandsDr.Ravi
 
Complete Guide for Linux shell programming
Complete Guide for Linux shell programmingComplete Guide for Linux shell programming
Complete Guide for Linux shell programmingsudhir singh yadav
 
Linux shell env
Linux shell envLinux shell env
Linux shell envRahul Pola
 
Shell Scripting in Linux
Shell Scripting in LinuxShell Scripting in Linux
Shell Scripting in LinuxAnu Chaudhry
 
Beautiful Bash: Let's make reading and writing bash scripts fun again!
Beautiful Bash: Let's make reading and writing bash scripts fun again!Beautiful Bash: Let's make reading and writing bash scripts fun again!
Beautiful Bash: Let's make reading and writing bash scripts fun again!Aaron Zauner
 
How to admin
How to adminHow to admin
How to adminyalegko
 
Perl one-liners
Perl one-linersPerl one-liners
Perl one-linersdaoswald
 
Unix Shell Scripting
Unix Shell ScriptingUnix Shell Scripting
Unix Shell ScriptingMustafa Qasim
 

La actualidad más candente (20)

COSCUP2012: How to write a bash script like the python?
COSCUP2012: How to write a bash script like the python?COSCUP2012: How to write a bash script like the python?
COSCUP2012: How to write a bash script like the python?
 
Bash shell
Bash shellBash shell
Bash shell
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Shell programming 1.ppt
Shell programming  1.pptShell programming  1.ppt
Shell programming 1.ppt
 
OpenGurukul : Language : Shell Scripting
OpenGurukul : Language : Shell ScriptingOpenGurukul : Language : Shell Scripting
OpenGurukul : Language : Shell Scripting
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Intro to Linux Shell Scripting
Intro to Linux Shell ScriptingIntro to Linux Shell Scripting
Intro to Linux Shell Scripting
 
BASH Guide Summary
BASH Guide SummaryBASH Guide Summary
BASH Guide Summary
 
Scripting and the shell in LINUX
Scripting and the shell in LINUXScripting and the shell in LINUX
Scripting and the shell in LINUX
 
Unix Commands
Unix CommandsUnix Commands
Unix Commands
 
Complete Guide for Linux shell programming
Complete Guide for Linux shell programmingComplete Guide for Linux shell programming
Complete Guide for Linux shell programming
 
Linux shell env
Linux shell envLinux shell env
Linux shell env
 
Shell Scripting in Linux
Shell Scripting in LinuxShell Scripting in Linux
Shell Scripting in Linux
 
Beautiful Bash: Let's make reading and writing bash scripts fun again!
Beautiful Bash: Let's make reading and writing bash scripts fun again!Beautiful Bash: Let's make reading and writing bash scripts fun again!
Beautiful Bash: Let's make reading and writing bash scripts fun again!
 
Unix shell scripting tutorial
Unix shell scripting tutorialUnix shell scripting tutorial
Unix shell scripting tutorial
 
Shell script-sec
Shell script-secShell script-sec
Shell script-sec
 
How to admin
How to adminHow to admin
How to admin
 
Perl one-liners
Perl one-linersPerl one-liners
Perl one-liners
 
Unix Shell Scripting
Unix Shell ScriptingUnix Shell Scripting
Unix Shell Scripting
 

Similar a Hawk presentation

390aLecture05_12sp.ppt
390aLecture05_12sp.ppt390aLecture05_12sp.ppt
390aLecture05_12sp.pptmugeshmsd5
 
Shell Scripting crash course.pdf
Shell Scripting crash course.pdfShell Scripting crash course.pdf
Shell Scripting crash course.pdfharikrishnapolaki
 
One-Liners to Rule Them All
One-Liners to Rule Them AllOne-Liners to Rule Them All
One-Liners to Rule Them Allegypt
 
Unix And Shell Scripting
Unix And Shell ScriptingUnix And Shell Scripting
Unix And Shell ScriptingJaibeer Malik
 
Shell-Scripting-1.pdf
Shell-Scripting-1.pdfShell-Scripting-1.pdf
Shell-Scripting-1.pdfaznabi
 
Shell_Scripting.ppt
Shell_Scripting.pptShell_Scripting.ppt
Shell_Scripting.pptKiranMantri
 
VTU 3RD SEM UNIX AND SHELL PROGRAMMING SOLVED PAPERS
VTU 3RD SEM UNIX AND SHELL PROGRAMMING SOLVED PAPERSVTU 3RD SEM UNIX AND SHELL PROGRAMMING SOLVED PAPERS
VTU 3RD SEM UNIX AND SHELL PROGRAMMING SOLVED PAPERSvtunotesbysree
 
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 Foobrian_dailey
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboyKenneth Geisshirt
 
Commands and shell programming (3)
Commands and shell programming (3)Commands and shell programming (3)
Commands and shell programming (3)christ university
 
Wildcards, Simple Shell Programs and Shell Variables
Wildcards, Simple Shell Programs and Shell VariablesWildcards, Simple Shell Programs and Shell Variables
Wildcards, Simple Shell Programs and Shell VariablesGaurav Bisht
 

Similar a Hawk presentation (20)

Shell programming
Shell programmingShell programming
Shell programming
 
390aLecture05_12sp.ppt
390aLecture05_12sp.ppt390aLecture05_12sp.ppt
390aLecture05_12sp.ppt
 
Shell Scripting crash course.pdf
Shell Scripting crash course.pdfShell Scripting crash course.pdf
Shell Scripting crash course.pdf
 
Spsl by sasidhar 3 unit
Spsl by sasidhar  3 unitSpsl by sasidhar  3 unit
Spsl by sasidhar 3 unit
 
Linux And perl
Linux And perlLinux And perl
Linux And perl
 
Unix
UnixUnix
Unix
 
Shellscripting
ShellscriptingShellscripting
Shellscripting
 
One-Liners to Rule Them All
One-Liners to Rule Them AllOne-Liners to Rule Them All
One-Liners to Rule Them All
 
Linux
LinuxLinux
Linux
 
Unix And Shell Scripting
Unix And Shell ScriptingUnix And Shell Scripting
Unix And Shell Scripting
 
SHELL PROGRAMMING
SHELL PROGRAMMINGSHELL PROGRAMMING
SHELL PROGRAMMING
 
Shell-Scripting-1.pdf
Shell-Scripting-1.pdfShell-Scripting-1.pdf
Shell-Scripting-1.pdf
 
Shell_Scripting.ppt
Shell_Scripting.pptShell_Scripting.ppt
Shell_Scripting.ppt
 
VTU 3RD SEM UNIX AND SHELL PROGRAMMING SOLVED PAPERS
VTU 3RD SEM UNIX AND SHELL PROGRAMMING SOLVED PAPERSVTU 3RD SEM UNIX AND SHELL PROGRAMMING SOLVED PAPERS
VTU 3RD SEM UNIX AND SHELL PROGRAMMING SOLVED PAPERS
 
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
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboy
 
First steps in C-Shell
First steps in C-ShellFirst steps in C-Shell
First steps in C-Shell
 
Commands and shell programming (3)
Commands and shell programming (3)Commands and shell programming (3)
Commands and shell programming (3)
 
Wildcards, Simple Shell Programs and Shell Variables
Wildcards, Simple Shell Programs and Shell VariablesWildcards, Simple Shell Programs and Shell Variables
Wildcards, Simple Shell Programs and Shell Variables
 
Linux com
Linux comLinux com
Linux com
 

Último

Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 

Último (20)

Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

Hawk presentation

  • 1. Haskell-awk Haskell text processor for the commandline Mario Pastorelli
  • 3. awk a generic text processor where “A file is treated as a sequence of records, and by default each line is a record.” - Alfred V. Aho developed in 1977 by Alfred Aho, Peter Weinberger, and Brian Kernighan @ Bell Labs uses AWK as programming language ak'EI {pit"el Wrd"} w BGN rn Hlo ol! ' procedural interpreted a program is a series of pattern action pairs
  • 4. Why another awk? “Whenever faced with a problem, some people say `Lets use AWK.' Now, they have two problems.” - D. Tilbrook avoid the AWK programming language use a generic language, not a DSL BGNslt" bcca,)frii abai]1r";o( i brr ";rn r EI{pi(a "a;o( n )[[]=;="fri n )=" ipit } nb$wrs" bcca u od a " procedural (imperative) vs functional programming for stream processing
  • 5. Haskell-awk (Hawk) a generic text processor where “A stream is treated as a sequence of records, and by default each line is a record.” the same philosophy of awk! developed in 2013 by me and Samuel Gélineau, the name is a tribute to awk uses Haskell as programming language hw 'HloWrd" ak "el ol!' functional (incrementally) compiled a program is a Haskell expression
  • 6. Why Haskell expressive, clean and concise >fle od[,,,] itr d 1234 [,] 13 functions as composable building blocks >ltwrCut=sm.mp(egh.wrs .lns e odon u a lnt od) ie >:yewrCut tp odon wrCut: Srn - It odon : tig > n >wrCut" 23n 56n 89 odon 1 4 7 " 9 partial application >:yemp tp a mp: ( - b - []- [] a : a > ) > a > b >:yent tp o nt: Bo - Bo o : ol > ol >:yempnt tp a o mpnt: [ol - [ol a o : Bo] > Bo] >mpnt[reFle a o Tu,as] [as,re FleTu] point-free style, laziness ...
  • 8. Modes evaluate an expression $hw '' ak 1 1 $hw '12' ak [,] 1 2 $hw '[,][,]' ak [12,34]' 12 34 apply an expression to the input $eh '2n'|hw - '.ees' co 1n3 ak a Lrvre 3 2 1 map an expression to each record of the input $eh ' 2n 4 |hw - '.ees' co 1 3 ' ak m Lrvre 21 43
  • 9. IO format The input is, by default, a list of list of strings where lines are separated by n and words by spaces $eh ' 2n 4 |hw - 'hw co 1 3 ' ak a so' ["""",""""] [1,2][3,4] Options -d/-D are provided to change delimiters or set them to empty $eh ',;,'|hw - -''-'''hw co 1234 ak a d, D; so' ["""",""""] [1,2][3,4] $eh ' 2n 4 |hw - -' 'hw co 1 3 ' ak a d' so' [12,34] " "" " $eh ' 2n 4 |hw - -' -' 'hw co 1 3 ' ak a d' D' so' " 2n 4n 1 3 " The output can be any type that instantiate the typeclass Rows cas(hwa = Rw awee ls So ) > os hr rp : BtSrn - a- [yetig er : yetig > > BtSrn]
  • 10. Examples get all users of a UNIX system $ct/t/asd|hw -:- '.ed a ecpsw ak d m Lha' ro ot deo amn .. . select username and userid $ct/t/asd|hw -:-'t - 'l- ( ! 0l! 2' a ecpsw ak d o' m > l ! , ! ) ro ot 0 deo 1 amn .. . sort by username (instead of pid) $ct/t/asd|hw -:- '.oty(opr `n Lha) a ecpsw ak d a LsrB cmae o` .ed' bnx22bn/i:bns i::::i:bn/i/h deo::::amn/s/bn/i/h amnx11deo:ursi:bns .. . get the number of users using each shell >ct/t/asd|hw -d '.a (.ed&&Llnt).Lgop.Lsr .LmpLls' a ecpsw ak a: Lmp Lha & .egh .ru .ot .a .at /i/ah1 bnbs: .. .
  • 11. Context Hawk can be customized using files inside the context directory (by default ~/.hawk) The most important file is prelude.hs that contains the "runtime context" $ct~.akpeueh a /hw/rld.s {#LNUG EtneDfutue,OelaeSrns#} - AGAE xeddealRls vroddtig ipr Peue mot rld ipr qaiidDt.yetigLz.hr a B mot ulfe aaBtSrn.ayCa8 s ipr qaiidDt.ita L mot ulfe aaLs s for instance, we can add a function for taking elements in an interval $eh 'aeewe se=Ltk ( -s .Ldo s > ~.akpeueh co tkBten .ae e ) .rp ' > /hw/rld.s $sq010|hw - 'aeewe 24 e 0 ak a tkBten ' 2 3
  • 13. Hawk must be fast cache the context use the timestamp to check if the context is changed since last run compile it with ghc use locks to compile only once when multiple Hawk instances instances are running hw '1.'|hw - '.ae3 ak [.] ak a Ltk ' use ByteString instead of String ...
  • 14. Parse and interpret Haskell Hawk combines two Haskell libraries haskell-src-exts to deal with haskell source code >ipr Lnug.akl.xsPre mot agaeHselEt.asr >gtoPams"- LNUG NIpiiPeueOelaeSrns#}n eTprga {# AGAE omlctrld,vroddtig -" Prek[agaerga(rLc asO LnugPam Sco {rFlnm ="nnw.s,scie=1 scoun=1) scieae ukonh" rLn , rClm } [dn "omlctrld"Iet"vroddtig"] Iet NIpiiPeue,dn OelaeSrns] hint to interpret the user expression >ipr Lnug.akl.nepee mot agaeHselItrrtr >rnnepee $stmot [Dt.n" > itrrt""(s: It uItrrtr eIprs "aaIt] > nepe 1 a : n) Rgt1 ih >rnnepee $stmot [Dt.n" > itrrt"o"(s: It uItrrtr eIprs "aaIt] > nepe fo a : n) Lf (otopl [hErr{rMg="o i soe `o'}) et WnCmie Gcro ers Nt n cp: fo"]