SlideShare a Scribd company logo
1 of 137
Harness the power of




                                   Sed & Awk
                                        Everything a PHP developer should know about sed & awk




                                                                                            Edition: PHPBenelux, jan 29, 2011, Antwerp

http://en.wikipedia.org/wiki/File:Slender_Loris.jpg                                        Sed & Awk - http://joind.in/2489
First, who am I?




                   Sed & Awk - http://joind.in/2489
First, who am I?




                   Sed & Awk - http://joind.in/2489
First, who am I?
Joshua Thijssen (32)




                                     Sed & Awk - http://joind.in/2489
First, who am I?
Joshua Thijssen (32)

Senior Software Engineer currently working
at Enrise (4worx)




                                             Sed & Awk - http://joind.in/2489
First, who am I?
Joshua Thijssen (32)

Senior Software Engineer currently working
at Enrise (4worx)

Development in PHP, Python, Perl, C, java,
assembly.




                                             Sed & Awk - http://joind.in/2489
First, who am I?
Joshua Thijssen (32)

Senior Software Engineer currently working
at Enrise (4worx)

Development in PHP, Python, Perl, C, java,
assembly.

Certified MySQL DBE, MySQL DBA,
LPIC-1, LPIC-2, Zend PHP5, Zend PHP5.3,
Zend Framework, Ubuntu professional.




                                             Sed & Awk - http://joind.in/2489
First, who am I?
Joshua Thijssen (32)

Senior Software Engineer currently working
at Enrise (4worx)

Development in PHP, Python, Perl, C, java,
assembly.

Certified MySQL DBE, MySQL DBA,
LPIC-1, LPIC-2, Zend PHP5, Zend PHP5.3,
Zend Framework, Ubuntu professional.

Blogs: http://www.adayinthelifeof.nl




                                             Sed & Awk - http://joind.in/2489
First, who am I?
Joshua Thijssen (32)

Senior Software Engineer currently working
at Enrise (4worx)

Development in PHP, Python, Perl, C, java,
assembly.

Certified MySQL DBE, MySQL DBA,
LPIC-1, LPIC-2, Zend PHP5, Zend PHP5.3,
Zend Framework, Ubuntu professional.

Blogs: http://www.adayinthelifeof.nl
       http://www.enrise.com/blog




                                             Sed & Awk - http://joind.in/2489
First, who am I?
Joshua Thijssen (32)

Senior Software Engineer currently working
at Enrise (4worx)

Development in PHP, Python, Perl, C, java,
assembly.

Certified MySQL DBE, MySQL DBA,
LPIC-1, LPIC-2, Zend PHP5, Zend PHP5.3,
Zend Framework, Ubuntu professional.

Blogs: http://www.adayinthelifeof.nl
       http://www.enrise.com/blog

Email:   joshua@enrise.com




                                             Sed & Awk - http://joind.in/2489
First, who am I?
Joshua Thijssen (32)

Senior Software Engineer currently working
at Enrise (4worx)

Development in PHP, Python, Perl, C, java,
assembly.

Certified MySQL DBE, MySQL DBA,
LPIC-1, LPIC-2, Zend PHP5, Zend PHP5.3,
Zend Framework, Ubuntu professional.

Blogs: http://www.adayinthelifeof.nl
       http://www.enrise.com/blog

Email: joshua@enrise.com
Twitter: @jaytaph


                                             Sed & Awk - http://joind.in/2489
Comfort zones




http://www.flickr.com/photos/gingerblokey/3597880429/sizes/l/in/photostream/   Sed & Awk - http://joind.in/2489
Comfort zones




http://www.flickr.com/photos/gingerblokey/3597880429/sizes/l/in/photostream/   Sed & Awk - http://joind.in/2489
Comfort zones




http://www.gnux-consultant.fr/service/fileadmin/templates/template_fr_1_FILES/elephant-php.gif   Sed & Awk - http://joind.in/2489
Comfort zones

    You are a PHP programmer...




http://www.gnux-consultant.fr/service/fileadmin/templates/template_fr_1_FILES/elephant-php.gif   Sed & Awk - http://joind.in/2489
Comfort zones

    You are a PHP programmer...


                                    ...so you program in PHP

http://www.gnux-consultant.fr/service/fileadmin/templates/template_fr_1_FILES/elephant-php.gif   Sed & Awk - http://joind.in/2489
Comfort zones

    You are a PHP programmer...


                                    ...so you program in PHP

http://www.gnux-consultant.fr/service/fileadmin/templates/template_fr_1_FILES/elephant-php.gif   Sed & Awk - http://joind.in/2489
Comfort zones

    You are a PHP programmer...


                                    ...so you program in PHP

http://www.gnux-consultant.fr/service/fileadmin/templates/template_fr_1_FILES/elephant-php.gif   Sed & Awk - http://joind.in/2489
Comfort zones

You are doing this already:




                              Sed & Awk - http://joind.in/2489
Comfort zones

You are doing this already:


  • SQL (where, order, limit, join)




                                      Sed & Awk - http://joind.in/2489
Comfort zones

You are doing this already:


  • SQL (where, order, limit, join)
  • Frameworks (Zend, Symfony, etc)



                                      Sed & Awk - http://joind.in/2489
Comfort zones

You are doing this already:


  • SQL (where, order, limit, join)
  • Frameworks (Zend, Symfony, etc)
  • JQuery, Dojo, etc


                                      Sed & Awk - http://joind.in/2489
Comfort zones
But why learn new stuff when you can do it in PHP?




                                       Sed & Awk - http://joind.in/2489
Comfort zones
But why learn new stuff when you can do it in PHP?

 ✓ Might be easier to use...




                                       Sed & Awk - http://joind.in/2489
Comfort zones
But why learn new stuff when you can do it in PHP?

 ✓ Might be easier to use...
 ✓ Might be faster to write...




                                       Sed & Awk - http://joind.in/2489
Comfort zones
But why learn new stuff when you can do it in PHP?

 ✓ Might be easier to use...
 ✓ Might be faster to write...
 ✓ Might be better suited for the job...



                                       Sed & Awk - http://joind.in/2489
Comfort zones
But why learn new stuff when you can do it in PHP?

 ✓ Might be easier to use...
 ✓ Might be faster to write...
 ✓ Might be better suited for the job...
 ✓ More efficient


                                       Sed & Awk - http://joind.in/2489
Comfort zones




!
                    Sed & Awk - http://joind.in/2489
Comfort zones

    I don’t want to tell you HOW to use Sed & Awk.




!
                                         Sed & Awk - http://joind.in/2489
Comfort zones

    I don’t want to tell you HOW to use Sed & Awk.

    I want to tell you that for certain jobs, tools
    like Sed & Awk are much better suited than
    PHP.


!
                                              Sed & Awk - http://joind.in/2489
Comfort zones

    I don’t want to tell you HOW to use Sed & Awk.

    I want to tell you that for certain jobs, tools
    like Sed & Awk are much better suited than
    PHP.


!   Know the capabilities of your tools and you
    become a better developer...


                                              Sed & Awk - http://joind.in/2489
Comfort zones

Why Sed & Awk?




                 Sed & Awk - http://joind.in/2489
Comfort zones

         Why Sed & Awk?
✓Useful for data manipulation




                                Sed & Awk - http://joind.in/2489
Comfort zones

         Why Sed & Awk?
✓Useful for data manipulation
✓They work well together



                                Sed & Awk - http://joind.in/2489
Comfort zones

         Why Sed & Awk?
✓Useful for data manipulation
✓They work well together
✓Both have a similar processing method


                                  Sed & Awk - http://joind.in/2489
Comfort zones

         Why Sed & Awk?
✓Useful for data manipulation
✓They work well together
✓Both have a similar processing method
✓Both rely heavily on regular expressions

                                   Sed & Awk - http://joind.in/2489
Comfort zones

         Why Sed & Awk?
✓Useful for data manipulation
✓They work well together
✓Both have a similar processing method
✓Both rely heavily on regular expressions
✓Nobody really harvest their power
                                   Sed & Awk - http://joind.in/2489
Part I : SED




http://www.flickr.com/photos/joachim_s_mueller/4298348196/        Sed & Awk - http://joind.in/2489
SED




      Sed & Awk - http://joind.in/2489
SED

• is a Stream EDitor




                       Sed & Awk - http://joind.in/2489
SED

• is a Stream EDitor
• applies rules based on a stream of data
  (per line)




                                     Sed & Awk - http://joind.in/2489
SED

• is a Stream EDitor
• applies rules based on a stream of data
  (per line)
• there is no turning back into the stream
  (going forward only)




                                     Sed & Awk - http://joind.in/2489
Why use SED?
Useful for:




                             Sed & Awk - http://joind.in/2489
Why use SED?
Useful for:
• Changing IP addresses or other data through many files.
  mutation of large datasets




                                                   Sed & Awk - http://joind.in/2489
Why use SED?
Useful for:
• Changing IP addresses or other data through many files.
  mutation of large datasets


• complex findin&certain blocks of code/data (for instance,
  Only change data
                   replace
   CSV, TXT, SQL files, docblocks etc)




                                                   Sed & Awk - http://joind.in/2489
Why use SED?
Useful for:
• Changing IP addresses or other data through many files.
  mutation of large datasets


• complex findin&certain blocks of code/data (for instance,
  Only change data
                   replace
   CSV, TXT, SQL files, docblocks etc)


• complexthe next 10 lines after each 404 code read from an
  Only print
             retrieval of data
   apache log file or print all docblocks and function headers



                                                     Sed & Awk - http://joind.in/2489
When use SED?
Use sed when:




Don’t use sed when:



                          Sed & Awk - http://joind.in/2489
When use SED?
Use sed when:
   •  When you need to change hundreds or
      thousands of files
   • “Complex” mutations
   • Fast “one liners” in scripts
Don’t use sed when:
   •  When you need to change one or two items
   • When you need aggregation or variables
                                     Sed & Awk - http://joind.in/2489
SED
        Most common example:


sed ‘s/foo/bar/g’ old > new




 changes ‘foo’ into ‘bar’ throughout the
file ‘old’ and places output into file ‘new’
                                    Sed & Awk - http://joind.in/2489
SED

$ cat foo.txt
foo bar foo
bar foo bar
foo bar foo
bar bar foo
foo foo bar
$ sed 's/foo/bar/g' foo.txt
bar bar bar
bar bar bar
bar bar bar
bar bar bar
bar bar bar




                              Sed & Awk - http://joind.in/2489
SED
    Another common example:


sed ‘s/foo//g’ old > new




   deletes ‘foo’ throughout the file
‘old’ and places output into file ‘new’
                                  Sed & Awk - http://joind.in/2489
SED

$ cat foo.txt
foo bar foo
bar foo bar
foo bar foo
bar bar foo
foo foo bar
$ sed 's/foo//g' foo.txt
 bar
bar bar
 bar
bar bar
  bar




                           Sed & Awk - http://joind.in/2489
SED
             A bit more advanced:


    sed ‘s/foo/FOO/2’ old > new




changes the second ‘foo’ on each line into ‘FOO’
                                      Sed & Awk - http://joind.in/2489
SED

$ cat foo.txt
foo bar foo
bar foo bar
foo bar foo
bar bar foo
foo foo bar
$ sed 's/foo/FOO/2' foo.txt
foo bar FOO
bar foo bar
foo bar FOO
bar bar foo
foo FOO bar




                              Sed & Awk - http://joind.in/2489
SED
      Sed can use address ranges:


 sed ‘1,3 s/foo/bar/g’ file




changes all ‘foo’s to ‘bar’s on lines 1 to 3

                                       Sed & Awk - http://joind.in/2489
SED

$ cat foo.txt
foo bar foo
bar foo bar
foo bar foo
bar bar foo
foo foo bar
$ sed '1,3 s/foo/bar/g' foo.txt
bar bar bar
bar bar bar
bar bar bar
bar bar foo
foo foo bar




                                  Sed & Awk - http://joind.in/2489
SED
    But you can also use a regex:


sed ‘1,/^$/ s/foo/bar/g’ file




     changes all ‘foo’s to ‘bar’s on
    lines 1 to the first empty line
                                       Sed & Awk - http://joind.in/2489
SED
$ cat foo.txt
foo bar foo
bar foo bar

foo bar foo
bar bar foo
foo foo bar
$ sed '1,/^$/ s/foo/bar/g' foo.txt
bar bar bar
bar bar bar

foo bar foo
bar bar foo
foo foo bar



                                     Sed & Awk - http://joind.in/2489
SED
$ cat foo.txt
foo bar foo
bar foo bar

foo bar foo
bar bar foo
foo foo bar
$ sed '/^$/,$ s/foo/bar/g' foo.txt
foo bar foo
bar foo bar

bar bar bar
bar bar bar
bar bar bar



                                     Sed & Awk - http://joind.in/2489
SED
   A ! negates the address range:


sed ‘1,3 ! s/foo/bar/g’ file




    changes all ‘foo’s to ‘bar’s on
    every line except lines 1 to 3
                                      Sed & Awk - http://joind.in/2489
SED

$ cat foo.txt
foo bar foo
bar foo bar
foo bar foo
bar bar foo
foo foo bar
$ sed '1,3 ! s/foo/bar/g' foo.txt
foo bar foo
bar foo bar
foo bar foo
bar bar bar
bar bar bar




                                    Sed & Awk - http://joind.in/2489
SED
     Multiple commands per range:


sed ‘1,3 { s/foo/bar/g ; s/.*/Line &/ ; }’ file



               sed ‘1,3 {
                 s/foo/bar/g
                 s/.*/Line &/
               }’ file

  for line 1 to 3: change foo’s into bar’s
      and prepend ‘Line’ to the line
                                      Sed & Awk - http://joind.in/2489
SED

$ cat foo.txt
foo bar foo
bar foo bar
foo bar foo
bar bar foo
foo foo bar
$ sed '1,3 { s/foo/bar/g ; s/.*/Line &/ ; }' foo.txt
Line bar bar bar
Line bar bar bar
Line bar bar bar
bar bar foo
foo foo bar




                                            Sed & Awk - http://joind.in/2489
SED
               Multiple ranges:
sed ‘1,3 s/foo/bar/g
     5,7 s/bar/foo/g
     s/(.*)/Line 1/’ file




    on line 1 to 3: change foo’s into bar’s
    on line 5 to 7: change bar’s into foo’s
   on all lines: add ‘Line’ in front of the line
                                          Sed & Awk - http://joind.in/2489
SED

$ cat foo.txt
foo bar foo
bar foo bar
foo bar foo
bar bar foo
foo foo bar
$ sed '1,3 s/foo/bar/g ; 5,7 s/bar/foo/g ; s/.*/Line: &/' foo.txt
Line: bar bar bar
Line: bar bar bar
Line: bar bar bar
Line: bar bar foo
Line: foo foo foo




                                                   Sed & Awk - http://joind.in/2489
SED

sed -n ‘
/^cut/ q
1,3 { s/foo/bar/g ; p ; }
4,$ { s/bar/foo/g ; p ; }
’ file




             -n means ‘don’t print’ lines

                                            Sed & Awk - http://joind.in/2489
SED

sed -n ‘
/^cut/ q
1,3 { s/foo/bar/g ; p ; }
4,$ { s/bar/foo/g ; p ; }
’ file




     if a line starts with ‘cut’, end processing

                                           Sed & Awk - http://joind.in/2489
SED

sed -n ‘
/^cut/ q
1,3 { s/foo/bar/g ; p ; }
4,$ { s/bar/foo/g ; p ; }
’ file




     line 1 to 3 will replace ‘foo’ to ‘bar’ and
              print the line to output
                                           Sed & Awk - http://joind.in/2489
SED

sed -n ‘
/^cut/ q
1,3 { s/foo/bar/g ; p ; }
4,$ { s/bar/foo/g ; p ; }
’ file




       line 4 to the end will replace ‘bar’ to
          ‘foo’ and print the line to output
                                          Sed & Awk - http://joind.in/2489
SED
$ cat file.txt
foo bar foo bar
bar bar foo foo
foo bar foo bar
bar bar foo foo
foo bar foo bar
foo bar foo bar
bar bar foo foo
bar bar foo foo
cut
this line is not added
$ sed -n '/^cut/ q ; 1,3 { s/foo/bar/g ; p ; } ; 4,$ { s/bar/foo/g ; p ; }' file.txt
bar bar bar bar
bar bar bar bar
bar bar bar bar
foo foo foo foo
foo foo foo foo
foo foo foo foo
foo foo foo foo
foo foo foo foo


                                                                   Sed & Awk - http://joind.in/2489
SED commands
a   append ‘text’ to output
s   substitute data
y   transform data (like ‘tr’)
d   delete line (don’t print)
n   (print) and goto next line
N   (print) and add next line to pattern space
p   print pattern space
q   quit processing
r   copy contents of file to pattern space
#   comment
=   prints current line number
                                     Sed & Awk - http://joind.in/2489
Commenting out
[production]
...
    bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
    bootstrap.class = "Bootstrap"
    resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"

[staging : production]

[testing : production]
    phpSettings.display_startup_errors = 1
    phpSettings.display_errors = 1

[development : production]
    phpSettings.display_startup_errors = 1
...




sed '/^[testing/,/^[/ s/.*/# --- &/' application.ini


                                                                 Sed & Awk - http://joind.in/2489
Commenting out

sed '/^[testing/,/^[/ s/.*/# --- &/' application.ini

[production]
...
    bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
    bootstrap.class = "Bootstrap"
    resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"

[staging : production]

# --- [testing : production]
# ---    phpSettings.display_startup_errors = 1
# ---    phpSettings.display_errors = 1
# ---
# ---[development : production]
    phpSettings.display_startup_errors = 1
...




                                                                 Sed & Awk - http://joind.in/2489
Commenting out
sed '/^[testing/,/^[/ {
/^[/ b
/^$/ b
s/.*/# --- &/
}' application.ini
[production]
...
    bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
    bootstrap.class = "Bootstrap"
    resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"

[staging : production]

[testing : production]
# ---    phpSettings.display_startup_errors = 1
# ---    phpSettings.display_errors = 1

[development : production]
    phpSettings.display_startup_errors = 1
...

                                                                  Sed & Awk - http://joind.in/2489
SED flow control


b <label> Unconditionally branch to <label>
: <label> Set <label>
t <label> Conditionally branch to <label>




                                      Sed & Awk - http://joind.in/2489
SED flow control
solfege.txt               sed script
do                        sed '
re                       :loop
mi                       /$/ N
fa                        s/n */ /
so                       t loop
la                       ' solfege.txt
si
do
                                Pattern buffer



                                            Output


                               Sed & Awk - http://joind.in/2489
SED flow control
solfege.txt               sed script
do                        sed '
re                       :loop
mi                       /$/ N
fa                        s/n */ /
so                       t loop
la                       ' solfege.txt
si
do
                                Pattern buffer
do



                                            Output


                               Sed & Awk - http://joind.in/2489
SED flow control
solfege.txt               sed script
do                        sed '
re                       :loop
mi                       /$/ N
fa                        s/n */ /
so                       t loop
la                       ' solfege.txt
si
do
                                Pattern buffer
do



                                            Output


                               Sed & Awk - http://joind.in/2489
SED flow control
solfege.txt               sed script
do                        sed '
re                       :loop
mi                       /$/ N
fa                        s/n */ /
so                       t loop
la                       ' solfege.txt
si
do
                                Pattern buffer
do



                                            Output


                               Sed & Awk - http://joind.in/2489
SED flow control
solfege.txt               sed script
do                        sed '
re                       :loop
mi                       /$/ N
fa                        s/n */ /
so                       t loop
la                       ' solfege.txt
si
do
                                Pattern buffer
re 



                                            Output
do


                               Sed & Awk - http://joind.in/2489
SED flow control
solfege.txt               sed script
do                        sed '
re                       :loop
mi                       /$/ N
fa                        s/n */ /
so                       t loop
la                       ' solfege.txt
si
do
                                Pattern buffer
re 



                                            Output
do


                               Sed & Awk - http://joind.in/2489
SED flow control
solfege.txt               sed script
do                        sed '
re                       :loop
mi                       /$/ N
fa                        s/n */ /
so                       t loop
la                       ' solfege.txt
si
do
                                Pattern buffer
re 
mi 


                                            Output
do


                               Sed & Awk - http://joind.in/2489
SED flow control
solfege.txt               sed script
do                        sed '
re                       :loop
mi                       /$/ N
fa                        s/n */ /
so                       t loop
la                       ' solfege.txt
si
do
                                Pattern buffer
re mi 



                                            Output
do


                               Sed & Awk - http://joind.in/2489
SED flow control
solfege.txt               sed script
do                        sed '
re                       :loop
mi                       /$/ N
fa                        s/n */ /
so                       t loop
la                       ' solfege.txt
si
do
                                Pattern buffer
re mi 



                                            Output
do


                               Sed & Awk - http://joind.in/2489
SED flow control
solfege.txt               sed script
do                        sed '
re                       :loop
mi                       /$/ N
fa                        s/n */ /
so                       t loop
la                       ' solfege.txt
si
do
                                Pattern buffer
re mi 
fa


                                            Output
do


                               Sed & Awk - http://joind.in/2489
SED flow control
solfege.txt               sed script
do                        sed '
re                       :loop
mi                       /$/ N
fa                        s/n */ /
so                       t loop
la                       ' solfege.txt
si
do
                                Pattern buffer
re mi fa



                                            Output
do


                               Sed & Awk - http://joind.in/2489
SED flow control
solfege.txt               sed script
do                        sed '
re                       :loop
mi                       /$/ N
fa                        s/n */ /
so                       t loop
la                       ' solfege.txt
si
do
                                Pattern buffer
re mi fa



                                            Output
do


                               Sed & Awk - http://joind.in/2489
SED flow control
solfege.txt               sed script
do                        sed '
re                       :loop
mi                       /$/ N
fa                        s/n */ /
so                       t loop
la                       ' solfege.txt
si
do
                                Pattern buffer
re mi fa



                                            Output
do


                               Sed & Awk - http://joind.in/2489
SED flow control
solfege.txt               sed script
do                        sed '
re                       :loop
mi                       /$/ N
fa                        s/n */ /
so                       t loop
la                       ' solfege.txt
si
do
                                Pattern buffer
re mi fa



                                            Output
do


                               Sed & Awk - http://joind.in/2489
SED flow control
solfege.txt               sed script
do                        sed '
re                       :loop
mi                       /$/ N
fa                        s/n */ /
so                       t loop
la                       ' solfege.txt
si
do
                                Pattern buffer
so 



                                            Output
do
re mi fa

                               Sed & Awk - http://joind.in/2489
Sed not powerful?
Delete all lines containing ‘regex’
sed '/regex/d' filename




Remove all additional white spaces
sed 's/ *$//' filename




Reverse all lines in a file (makes use of the hold buffer)
sed -n '1 ! G ; h ; $ p' filename



                                                      Sed & Awk - http://joind.in/2489
Sed not powerful?
                Meet Sedtris:
A fully functional Tetris clone written in SED




      http://uuner.doslash.org/forfun/
                                      Sed & Awk - http://joind.in/2489
So use sed when:




               Sed & Awk - http://joind.in/2489
So use sed when:


• Repetitive work on many files




                                 Sed & Awk - http://joind.in/2489
So use sed when:


• Repetitive work on many files
• “complex” mutations



                                 Sed & Awk - http://joind.in/2489
So use sed when:


• Repetitive work on many files
• “complex” mutations
• Fast “oneliners” in scripts etc..


                                      Sed & Awk - http://joind.in/2489
Part 2 : AWK




http://www.flickr.com/photos/joachim_s_mueller/138409464/in/photostream/   Sed & Awk - http://joind.in/2489
AWK




      Sed & Awk - http://joind.in/2489
AWK

• AWK is a full-fledged programming
  language.




                                 Sed & Awk - http://joind.in/2489
AWK

• AWK is a full-fledged programming
  language.
• There is NO way I can teach you AWK in
  +- 20 minutes




                                 Sed & Awk - http://joind.in/2489
AWK

• AWK is a full-fledged programming
   language.
• There is NO way I can teach you AWK in
   +- 20 minutes
• But i’ll try...


                                 Sed & Awk - http://joind.in/2489
AWK




      Sed & Awk - http://joind.in/2489
AWK
• Alfred V. Aho, Peter J.Weinberger, Brain W.
  Kernighan




                                     Sed & Awk - http://joind.in/2489
AWK
• Alfred V. Aho, Peter J.Weinberger, Brain W.
  Kernighan
• Written in 1977 at AT&T Bell Laboratories




                                     Sed & Awk - http://joind.in/2489
AWK
• Alfred V. Aho, Peter J.Weinberger, Brain W.
  Kernighan
• Written in 1977 at AT&T Bell Laboratories
• Multiple versions: AWK, NAWK, GAWK,
  MAWK and more...




                                     Sed & Awk - http://joind.in/2489
AWK
• Alfred V. Aho, Peter J.Weinberger, Brain W.
  Kernighan
• Written in 1977 at AT&T Bell Laboratories
• Multiple versions: AWK, NAWK, GAWK,
  MAWK and more...
• Pattern-directed scanning and processing
  language...



                                     Sed & Awk - http://joind.in/2489
AWK




      Sed & Awk - http://joind.in/2489
AWK


• [condition] { actions }




                            Sed & Awk - http://joind.in/2489
AWK


• [condition] { actions }
• 2 special “patterns” : BEGIN and END



                                   Sed & Awk - http://joind.in/2489
Simple AWK
$ cat solfege.txt
do
re
mi
fa
sol
la
ti
do
$ awk '
BEGIN { print "start" }
/o/ { print "I just saw an o in " $0 }
END { print "the end" }' solfege.txt
start
I just saw an o in do
I just saw an o in sol
I just saw an o in do
the end




                                         Sed & Awk - http://joind.in/2489
Apache logfile (combined)
   Awk processes through “records” and “fields”
72.30.161.230 - - [18/Jan/2011:20:28:09 +0100] "GET /robots.txt HTTP/1.0" 200 387
"-" "Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/
slurp)"
72.30.161.230 - - [18/Jan/2011:20:28:10 +0100] "GET / HTTP/1.0" 200 7235 "-"
"Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/
slurp)"




   you can control the record and field separators



                                                                Sed & Awk - http://joind.in/2489
Apache logfile (combined)
72.30.161.230
-
-
[18/Jan/2011:20:28:09
+0100]
"GET
/robots.txt
HTTP/1.0"
200
387
"-"
"Mozilla/5.0
(compatible;
Yahoo!
Slurp;
http://help.yahoo.com/help/us/ysearch/slurp)"




72.30.161.230 - - [18/Jan/2011:20:28:10 +0100] "GET / HTTP/1.0" 200 7235 "-" "Mozilla/5.0
(compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)"




                          Field separator “space”
                                                                              Sed & Awk - http://joind.in/2489
Apache logfile (combined)


72.30.161.230 - - [18/Jan/2011:20:28:09 +0100]
GET /robots.txt HTTP/1.0
200 387
-

Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)




72.30.161.230 - - [18/Jan/2011:20:28:10 +0100] "GET / HTTP/1.0" 200 7235 "-" "Mozilla/5.0
(compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)"




                  Field separator “double quote” (“)
                                                                              Sed & Awk - http://joind.in/2489
Some global AWK knowledge




                    Sed & Awk - http://joind.in/2489
Some global AWK knowledge

• You can set the field and record separator




                                   Sed & Awk - http://joind.in/2489
Some global AWK knowledge

• You can set the field and record separator
• $FS=”|”; $RS=”t”




                                   Sed & Awk - http://joind.in/2489
Some global AWK knowledge

• You can set the field and record separator
• $FS=”|”; $RS=”t”
• $0 holds the complete record (line)



                                   Sed & Awk - http://joind.in/2489
Some global AWK knowledge

• You can set the field and record separator
• $FS=”|”; $RS=”t”
• $0 holds the complete record (line)
• $1 holds first field, $2 second field etc...


                                   Sed & Awk - http://joind.in/2489
Some global AWK knowledge

• You can set the field and record separator
• $FS=”|”; $RS=”t”
• $0 holds the complete record (line)
• $1 holds first field, $2 second field etc...
• $NF holds number of fields in record

                                   Sed & Awk - http://joind.in/2489
Some global AWK knowledge

• You can set the field and record separator
• $FS=”|”; $RS=”t”
• $0 holds the complete record (line)
• $1 holds first field, $2 second field etc...
• $NF holds number of fields in record
• $NR holds CURRENT record
                                   Sed & Awk - http://joind.in/2489
Apache logfile (combined)

          Print the “user agents” from the logfile

$ awk -F" '{ print $6 }' apache.log
Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)
Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322) NS8/0.9.6
Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)
Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322) NS8/0.9.6
Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)
Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)
Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)
Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)




                                                                     Sed & Awk - http://joind.in/2489
Apache logfile (combined)
          Print the “user agents” from the logfile
         and count them (through external tools)


$ awk -F" '{ print   $6 }' apache.log | sort | uniq -c
      2 Mozilla/4.0   (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322) NS8/0.9.6
      1 Mozilla/5.0   (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
      7 Mozilla/5.0   (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)




                                                                           Sed & Awk - http://joind.in/2489
Apache logfile (combined)
    Print the total bytes send out per status code

$ awk   -F '{ totals[$9] += $10; }
END {   for (i in totals) { printf "%d : %d bytesn", i, totals[i]; } }' apache.log
200 :   26197250 bytes
206 :   180578 bytes
301 :   31072 bytes
302 :   2991 bytes
304 :   44715 bytes
404 :   82866 bytes
500 :   361783 bytes




                                                                           Sed & Awk - http://joind.in/2489
Apache logfile (combined)
          Print the “user agents” from the logfile
                 who triggered a 4xx code

$ awk -F '$9 ~ /4[0-9][0-9]/ { FS="""; $0=$0; print $6; FS=" " }' apache.log
Googlebot/2.1 (+http://www.googlebot.com/bot.html)
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6
libwww-perl/5.805
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6
Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8b4) Gecko/20050908 Firefox/1.4
Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8b4) Gecko/20050908 Firefox/1.4
Googlebot/2.1 (+http://www.googlebot.com/bot.html)
Googlebot/2.1 (+http://www.googlebot.com/bot.html)
Googlebot/2.1 (+http://www.googlebot.com/bot.html)
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)




                                                                         Sed & Awk - http://joind.in/2489
Apache logfile (combined)

                                    Awk one liner compared to PHP:
       $ awk -F      '{ totals[$9] += $10; } END { for (i in totals) { printf "%d : %d bytesn", i, totals[i]; } }' apache.log


       <?php

       $hash = array();
       foreach( file( './apache.log' ) as $line ) {
       	    list( , , , , , , , , $status, $bytes ) = explode( ' ', $line );
       	
       	    if( !isset( $hash[$status] ) ) {
       	    	    $hash[$status] = 0;
       	    }
       	
       	    $hash[$status] += $bytes;
       }
       print_r($hash);




                      Not a whole lot different, but already more
                     complex and this was just a simple example...

credits to @RichardJ #pfz channel                                                                      Sed & Awk - http://joind.in/2489
Apache logfile (combined)

                                    Sed one liner compared to PHP:

         sed ‘/^.o/d’ file



         <?php
             $stdin = fopen("php://stdin", "r");
             while (!feof($stdin)) {
                 $line = fgets($stdin);
                 if (preg_match("/^.o/", $line)) continue;
                 print $line;
             }
         ?>




                                           Much more work....

credits to @RichardJ #pfz channel                                Sed & Awk - http://joind.in/2489
Practical uses for a (PHP) developer


• parse php-errors files, syslog files, apache’s
  http access logs.
• Conversion of files you get from your
  customers, who always assume you can do
  magic with a gazzillion GB’s of (unsorted)
  data (and now you can).




                                      Sed & Awk - http://joind.in/2489
In conclusion: sed & awk




                    Sed & Awk - http://joind.in/2489
In conclusion: sed & awk

• are powerful for simple one-liners but can
  also be used for complex programs




                                    Sed & Awk - http://joind.in/2489
In conclusion: sed & awk

• are powerful for simple one-liners but can
  also be used for complex programs
• integrates perfectly with other (unix) tools
  like uniq, sort, cut, find, grep, cat, etc...




                                           Sed & Awk - http://joind.in/2489
In conclusion: sed & awk

• are powerful for simple one-liners but can
  also be used for complex programs
• integrates perfectly with other (unix) tools
  like uniq, sort, cut, find, grep, cat, etc...
• are a great way to automate complex and/
  or repetitive (editing) tasks



                                           Sed & Awk - http://joind.in/2489
In conclusion




http://files.sharenator.com/slender_loris_Worlds_strangest_looking_animals-s300x451-2279-580.jpg   Sed & Awk - http://joind.in/2489
In conclusion

               • Look outside your
                       comfort zone for other
                       (better) tools.




http://files.sharenator.com/slender_loris_Worlds_strangest_looking_animals-s300x451-2279-580.jpg   Sed & Awk - http://joind.in/2489
In conclusion

               • Look outside your
                       comfort zone for other
                       (better) tools.
               • Can you think of
                       examples where you
                       would use Sed or Awk
                       (instead of php?)



http://files.sharenator.com/slender_loris_Worlds_strangest_looking_animals-s300x451-2279-580.jpg   Sed & Awk - http://joind.in/2489
Questions?




http://static.squidoo.com/resize/squidoo_images/250/draft_lens2806042 
module29556622photo_1240639056fry-panique-questions.jpg                   Sed & Awk - http://joind.in/2489
Read more on Sed & Awk

Sed:
 http://www.gnu.org/software/sed/manual/html_node/index.html
 http://www.grymoire.com/Unix/Sed.html
 http://www.panix.com/~elflord/unix/sed.html
 http://www.linuxtopia.org/online_books/linux_tool_guides/the_sed_faq/index.html


Awk:
 http://www.gnu.org/software/gawk/
 http://www.grymoire.com/Unix/Awk.html




                                                             Sed & Awk - http://joind.in/2489
Thank you for your
      attention!

      Don’t forget to rate
      my talk on joind.in

      http://joind.in/2489


http://farm5.static.flickr.com/4078/4790219776_2fe3c9af95_b.jpg   Sed & Awk - http://joind.in/2489

More Related Content

What's hot

Introduction to shell scripting
Introduction to shell scriptingIntroduction to shell scripting
Introduction to shell scriptingCorrado Santoro
 
Bash shell scripting
Bash shell scriptingBash shell scripting
Bash shell scriptingVIKAS TIWARI
 
Bash shell
Bash shellBash shell
Bash shellxylas121
 
Linux Interview Questions And Answers | Linux Administration Tutorial | Linux...
Linux Interview Questions And Answers | Linux Administration Tutorial | Linux...Linux Interview Questions And Answers | Linux Administration Tutorial | Linux...
Linux Interview Questions And Answers | Linux Administration Tutorial | Linux...Edureka!
 
Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...
Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...
Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...Edureka!
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShellBoulos Dib
 
PowerShell 101
PowerShell 101PowerShell 101
PowerShell 101Thomas Lee
 
Linux programming lecture_notes
Linux programming lecture_notesLinux programming lecture_notes
Linux programming lecture_notesIMRAN KHAN
 
Linux Presentation
Linux PresentationLinux Presentation
Linux Presentationnishantsri
 
Red Hat Enterprise Linux 8
Red Hat Enterprise Linux 8Red Hat Enterprise Linux 8
Red Hat Enterprise Linux 8Kangaroot
 
Intro to Linux Shell Scripting
Intro to Linux Shell ScriptingIntro to Linux Shell Scripting
Intro to Linux Shell Scriptingvceder
 
How to Avoid the Top 5 NGINX Configuration Mistakes
How to Avoid the Top 5 NGINX Configuration MistakesHow to Avoid the Top 5 NGINX Configuration Mistakes
How to Avoid the Top 5 NGINX Configuration MistakesNGINX, Inc.
 
Introduction to Vim
Introduction to VimIntroduction to Vim
Introduction to VimBrandon Liu
 
Red hat enterprise linux 7 (rhel 7)
Red hat enterprise linux 7 (rhel 7)Red hat enterprise linux 7 (rhel 7)
Red hat enterprise linux 7 (rhel 7)Ramola Dhande
 

What's hot (20)

Introduction to shell scripting
Introduction to shell scriptingIntroduction to shell scripting
Introduction to shell scripting
 
PowerShell-1
PowerShell-1PowerShell-1
PowerShell-1
 
Bash shell scripting
Bash shell scriptingBash shell scripting
Bash shell scripting
 
Bash shell
Bash shellBash shell
Bash shell
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Linux Interview Questions And Answers | Linux Administration Tutorial | Linux...
Linux Interview Questions And Answers | Linux Administration Tutorial | Linux...Linux Interview Questions And Answers | Linux Administration Tutorial | Linux...
Linux Interview Questions And Answers | Linux Administration Tutorial | Linux...
 
Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...
Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...
Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShell
 
PowerShell 101
PowerShell 101PowerShell 101
PowerShell 101
 
Linux programming lecture_notes
Linux programming lecture_notesLinux programming lecture_notes
Linux programming lecture_notes
 
Linux Presentation
Linux PresentationLinux Presentation
Linux Presentation
 
Red Hat Enterprise Linux 8
Red Hat Enterprise Linux 8Red Hat Enterprise Linux 8
Red Hat Enterprise Linux 8
 
Intro to Linux Shell Scripting
Intro to Linux Shell ScriptingIntro to Linux Shell Scripting
Intro to Linux Shell Scripting
 
Basic 50 linus command
Basic 50 linus commandBasic 50 linus command
Basic 50 linus command
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
How to Avoid the Top 5 NGINX Configuration Mistakes
How to Avoid the Top 5 NGINX Configuration MistakesHow to Avoid the Top 5 NGINX Configuration Mistakes
How to Avoid the Top 5 NGINX Configuration Mistakes
 
Introduction to Vim
Introduction to VimIntroduction to Vim
Introduction to Vim
 
An Introduction To Linux
An Introduction To LinuxAn Introduction To Linux
An Introduction To Linux
 
Windows 2019
Windows 2019Windows 2019
Windows 2019
 
Red hat enterprise linux 7 (rhel 7)
Red hat enterprise linux 7 (rhel 7)Red hat enterprise linux 7 (rhel 7)
Red hat enterprise linux 7 (rhel 7)
 

Viewers also liked

Unix command-line tools
Unix command-line toolsUnix command-line tools
Unix command-line toolsEric Wilson
 
Practical Example of grep command in unix
Practical Example of grep command in unixPractical Example of grep command in unix
Practical Example of grep command in unixJavin Paul
 
Web Application Security with PHP
Web Application Security with PHPWeb Application Security with PHP
Web Application Security with PHPjikbal
 
Defeating The Network Security Infrastructure V1.0
Defeating The Network Security Infrastructure  V1.0Defeating The Network Security Infrastructure  V1.0
Defeating The Network Security Infrastructure V1.0Philippe Bogaerts
 
Practical unix utilities for text processing
Practical unix utilities for text processingPractical unix utilities for text processing
Practical unix utilities for text processingAnton Arhipov
 
Web Application Security: Introduction to common classes of security flaws an...
Web Application Security: Introduction to common classes of security flaws an...Web Application Security: Introduction to common classes of security flaws an...
Web Application Security: Introduction to common classes of security flaws an...Thoughtworks
 
Unix Command Line Productivity Tips
Unix Command Line Productivity TipsUnix Command Line Productivity Tips
Unix Command Line Productivity TipsKeith Bennett
 
Secure Shell(ssh)
Secure Shell(ssh)Secure Shell(ssh)
Secure Shell(ssh)Pina Parmar
 
Virtual Security Lab Setup - OWASP Broken Web Apps, Webgoat, & ZAP
Virtual Security Lab Setup - OWASP Broken Web Apps, Webgoat, & ZAPVirtual Security Lab Setup - OWASP Broken Web Apps, Webgoat, & ZAP
Virtual Security Lab Setup - OWASP Broken Web Apps, Webgoat, & ZAPMichael Coates
 
Top 100 Linux Interview Questions and Answers 2014
Top 100 Linux Interview Questions and Answers 2014Top 100 Linux Interview Questions and Answers 2014
Top 100 Linux Interview Questions and Answers 2014iimjobs and hirist
 
RHCE FINAL Questions and Answers
RHCE FINAL Questions and AnswersRHCE FINAL Questions and Answers
RHCE FINAL Questions and AnswersRadien software
 
Introduction to SSH
Introduction to SSHIntroduction to SSH
Introduction to SSHHemant Shah
 
Linux Systems Performance 2016
Linux Systems Performance 2016Linux Systems Performance 2016
Linux Systems Performance 2016Brendan Gregg
 

Viewers also liked (20)

PHP Secure Programming
PHP Secure ProgrammingPHP Secure Programming
PHP Secure Programming
 
Secure SHell
Secure SHellSecure SHell
Secure SHell
 
Unix command-line tools
Unix command-line toolsUnix command-line tools
Unix command-line tools
 
Practical Example of grep command in unix
Practical Example of grep command in unixPractical Example of grep command in unix
Practical Example of grep command in unix
 
Web Application Security with PHP
Web Application Security with PHPWeb Application Security with PHP
Web Application Security with PHP
 
Defeating The Network Security Infrastructure V1.0
Defeating The Network Security Infrastructure  V1.0Defeating The Network Security Infrastructure  V1.0
Defeating The Network Security Infrastructure V1.0
 
Practical unix utilities for text processing
Practical unix utilities for text processingPractical unix utilities for text processing
Practical unix utilities for text processing
 
Web Application Security: Introduction to common classes of security flaws an...
Web Application Security: Introduction to common classes of security flaws an...Web Application Security: Introduction to common classes of security flaws an...
Web Application Security: Introduction to common classes of security flaws an...
 
Unix Command Line Productivity Tips
Unix Command Line Productivity TipsUnix Command Line Productivity Tips
Unix Command Line Productivity Tips
 
class12_Networking2
class12_Networking2class12_Networking2
class12_Networking2
 
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
 
Secure shell protocol
Secure shell protocolSecure shell protocol
Secure shell protocol
 
SSH
SSHSSH
SSH
 
Secure Shell(ssh)
Secure Shell(ssh)Secure Shell(ssh)
Secure Shell(ssh)
 
SSH - Secure Shell
SSH - Secure ShellSSH - Secure Shell
SSH - Secure Shell
 
Virtual Security Lab Setup - OWASP Broken Web Apps, Webgoat, & ZAP
Virtual Security Lab Setup - OWASP Broken Web Apps, Webgoat, & ZAPVirtual Security Lab Setup - OWASP Broken Web Apps, Webgoat, & ZAP
Virtual Security Lab Setup - OWASP Broken Web Apps, Webgoat, & ZAP
 
Top 100 Linux Interview Questions and Answers 2014
Top 100 Linux Interview Questions and Answers 2014Top 100 Linux Interview Questions and Answers 2014
Top 100 Linux Interview Questions and Answers 2014
 
RHCE FINAL Questions and Answers
RHCE FINAL Questions and AnswersRHCE FINAL Questions and Answers
RHCE FINAL Questions and Answers
 
Introduction to SSH
Introduction to SSHIntroduction to SSH
Introduction to SSH
 
Linux Systems Performance 2016
Linux Systems Performance 2016Linux Systems Performance 2016
Linux Systems Performance 2016
 

Similar to Sed & awk the dynamic duo

Standardizing and Managing Your Infrastructure - MOSC 2011
Standardizing and Managing Your Infrastructure - MOSC 2011Standardizing and Managing Your Infrastructure - MOSC 2011
Standardizing and Managing Your Infrastructure - MOSC 2011Brian Ritchie
 
The ART of Modern Azure Deployments
The ART of Modern Azure DeploymentsThe ART of Modern Azure Deployments
The ART of Modern Azure DeploymentsBizTalk360
 
What's New in Oracle SQL Developer for 2018
What's New in Oracle SQL Developer for 2018What's New in Oracle SQL Developer for 2018
What's New in Oracle SQL Developer for 2018Jeff Smith
 
CON5898 What Servlet 4.0 Means To You
CON5898 What Servlet 4.0 Means To YouCON5898 What Servlet 4.0 Means To You
CON5898 What Servlet 4.0 Means To YouEdward Burns
 
Grown-up javascript with AngularJS
Grown-up javascript with AngularJSGrown-up javascript with AngularJS
Grown-up javascript with AngularJSMykhailo Kotsur
 
A REST Layer on Top of the World - IPC13 Munich
A REST Layer on Top of the World - IPC13 MunichA REST Layer on Top of the World - IPC13 Munich
A REST Layer on Top of the World - IPC13 MunichNicolas Pastorino
 
AWS CDK introduction
AWS CDK introductionAWS CDK introduction
AWS CDK introductionleo lapworth
 
DEV305_Manage Your Applications with AWS Elastic Beanstalk.pdf
DEV305_Manage Your Applications with AWS Elastic Beanstalk.pdfDEV305_Manage Your Applications with AWS Elastic Beanstalk.pdf
DEV305_Manage Your Applications with AWS Elastic Beanstalk.pdfAmazon Web Services
 
Lviv .Net User Group. NHibernate
Lviv .Net User Group. NHibernateLviv .Net User Group. NHibernate
Lviv .Net User Group. NHibernateDima Maleev
 
Rails Presentation (Anton Dmitriyev)
Rails Presentation (Anton Dmitriyev)Rails Presentation (Anton Dmitriyev)
Rails Presentation (Anton Dmitriyev)True-Vision
 
Using Databases and Containers From Development to Deployment
Using Databases and Containers  From Development to DeploymentUsing Databases and Containers  From Development to Deployment
Using Databases and Containers From Development to DeploymentAerospike, Inc.
 
eZ Platform Cloud and eZ Launchpad: Don’t Host, Don’t Deploy, Don’t Install—J...
eZ Platform Cloud and eZ Launchpad: Don’t Host, Don’t Deploy, Don’t Install—J...eZ Platform Cloud and eZ Launchpad: Don’t Host, Don’t Deploy, Don’t Install—J...
eZ Platform Cloud and eZ Launchpad: Don’t Host, Don’t Deploy, Don’t Install—J...Sébastien Morel
 
eZ Platform Cloud and eZ Launchpad: Don’t Host, Don’t Deploy, Don’t Install—J...
eZ Platform Cloud and eZ Launchpad: Don’t Host, Don’t Deploy, Don’t Install—J...eZ Platform Cloud and eZ Launchpad: Don’t Host, Don’t Deploy, Don’t Install—J...
eZ Platform Cloud and eZ Launchpad: Don’t Host, Don’t Deploy, Don’t Install—J...eZ Systems
 
DevOps Columbus Meetup Kickoff - Infrastructure as Code
DevOps Columbus Meetup Kickoff - Infrastructure as CodeDevOps Columbus Meetup Kickoff - Infrastructure as Code
DevOps Columbus Meetup Kickoff - Infrastructure as CodeMichael Ducy
 
Introduction to NodeJS with LOLCats
Introduction to NodeJS with LOLCatsIntroduction to NodeJS with LOLCats
Introduction to NodeJS with LOLCatsDerek Anderson
 
Deploy Deep Learning Application with Azure Container Instance - Devdays2018
Deploy Deep Learning Application with Azure Container Instance - Devdays2018Deploy Deep Learning Application with Azure Container Instance - Devdays2018
Deploy Deep Learning Application with Azure Container Instance - Devdays2018Mia Chang
 
Contributing to rails
Contributing to railsContributing to rails
Contributing to railsLukas Eppler
 

Similar to Sed & awk the dynamic duo (20)

Standardizing and Managing Your Infrastructure - MOSC 2011
Standardizing and Managing Your Infrastructure - MOSC 2011Standardizing and Managing Your Infrastructure - MOSC 2011
Standardizing and Managing Your Infrastructure - MOSC 2011
 
The ART of Modern Azure Deployments
The ART of Modern Azure DeploymentsThe ART of Modern Azure Deployments
The ART of Modern Azure Deployments
 
What's New in Oracle SQL Developer for 2018
What's New in Oracle SQL Developer for 2018What's New in Oracle SQL Developer for 2018
What's New in Oracle SQL Developer for 2018
 
CON5898 What Servlet 4.0 Means To You
CON5898 What Servlet 4.0 Means To YouCON5898 What Servlet 4.0 Means To You
CON5898 What Servlet 4.0 Means To You
 
Grown-up javascript with AngularJS
Grown-up javascript with AngularJSGrown-up javascript with AngularJS
Grown-up javascript with AngularJS
 
A REST Layer on Top of the World - IPC13 Munich
A REST Layer on Top of the World - IPC13 MunichA REST Layer on Top of the World - IPC13 Munich
A REST Layer on Top of the World - IPC13 Munich
 
AWS CDK introduction
AWS CDK introductionAWS CDK introduction
AWS CDK introduction
 
DEV305_Manage Your Applications with AWS Elastic Beanstalk.pdf
DEV305_Manage Your Applications with AWS Elastic Beanstalk.pdfDEV305_Manage Your Applications with AWS Elastic Beanstalk.pdf
DEV305_Manage Your Applications with AWS Elastic Beanstalk.pdf
 
NHibernate
NHibernateNHibernate
NHibernate
 
Lviv .Net User Group. NHibernate
Lviv .Net User Group. NHibernateLviv .Net User Group. NHibernate
Lviv .Net User Group. NHibernate
 
Rails Presentation (Anton Dmitriyev)
Rails Presentation (Anton Dmitriyev)Rails Presentation (Anton Dmitriyev)
Rails Presentation (Anton Dmitriyev)
 
SD Times - Docker v2
SD Times - Docker v2SD Times - Docker v2
SD Times - Docker v2
 
Using Databases and Containers From Development to Deployment
Using Databases and Containers  From Development to DeploymentUsing Databases and Containers  From Development to Deployment
Using Databases and Containers From Development to Deployment
 
eZ Platform Cloud and eZ Launchpad: Don’t Host, Don’t Deploy, Don’t Install—J...
eZ Platform Cloud and eZ Launchpad: Don’t Host, Don’t Deploy, Don’t Install—J...eZ Platform Cloud and eZ Launchpad: Don’t Host, Don’t Deploy, Don’t Install—J...
eZ Platform Cloud and eZ Launchpad: Don’t Host, Don’t Deploy, Don’t Install—J...
 
eZ Platform Cloud and eZ Launchpad: Don’t Host, Don’t Deploy, Don’t Install—J...
eZ Platform Cloud and eZ Launchpad: Don’t Host, Don’t Deploy, Don’t Install—J...eZ Platform Cloud and eZ Launchpad: Don’t Host, Don’t Deploy, Don’t Install—J...
eZ Platform Cloud and eZ Launchpad: Don’t Host, Don’t Deploy, Don’t Install—J...
 
(ARC307) Infrastructure as Code
(ARC307) Infrastructure as Code(ARC307) Infrastructure as Code
(ARC307) Infrastructure as Code
 
DevOps Columbus Meetup Kickoff - Infrastructure as Code
DevOps Columbus Meetup Kickoff - Infrastructure as CodeDevOps Columbus Meetup Kickoff - Infrastructure as Code
DevOps Columbus Meetup Kickoff - Infrastructure as Code
 
Introduction to NodeJS with LOLCats
Introduction to NodeJS with LOLCatsIntroduction to NodeJS with LOLCats
Introduction to NodeJS with LOLCats
 
Deploy Deep Learning Application with Azure Container Instance - Devdays2018
Deploy Deep Learning Application with Azure Container Instance - Devdays2018Deploy Deep Learning Application with Azure Container Instance - Devdays2018
Deploy Deep Learning Application with Azure Container Instance - Devdays2018
 
Contributing to rails
Contributing to railsContributing to rails
Contributing to rails
 

More from Joshua Thijssen

Puppet for dummies - ZendCon 2011 Edition
Puppet for dummies - ZendCon 2011 EditionPuppet for dummies - ZendCon 2011 Edition
Puppet for dummies - ZendCon 2011 EditionJoshua Thijssen
 
Puppet for dummies - PHPBenelux UG edition
Puppet for dummies - PHPBenelux UG editionPuppet for dummies - PHPBenelux UG edition
Puppet for dummies - PHPBenelux UG editionJoshua Thijssen
 
15 protips for mysql users pfz
15 protips for mysql users   pfz15 protips for mysql users   pfz
15 protips for mysql users pfzJoshua Thijssen
 
Alice & bob public key cryptography 101 - uncon dpc
Alice & bob  public key cryptography 101 - uncon dpcAlice & bob  public key cryptography 101 - uncon dpc
Alice & bob public key cryptography 101 - uncon dpcJoshua Thijssen
 
Representation state transfer and some other important stuff
Representation state transfer and some other important stuffRepresentation state transfer and some other important stuff
Representation state transfer and some other important stuffJoshua Thijssen
 
Deploying and maintaining your software with RPM/APT
Deploying and maintaining your software with RPM/APTDeploying and maintaining your software with RPM/APT
Deploying and maintaining your software with RPM/APTJoshua Thijssen
 
Alice & bob public key cryptography 101
Alice & bob  public key cryptography 101Alice & bob  public key cryptography 101
Alice & bob public key cryptography 101Joshua Thijssen
 
15 protips for mysql users
15 protips for mysql users15 protips for mysql users
15 protips for mysql usersJoshua Thijssen
 
Alice & bob public key cryptography 101
Alice & bob  public key cryptography 101Alice & bob  public key cryptography 101
Alice & bob public key cryptography 101Joshua Thijssen
 
PFZ WorkshopDay Linux - Advanced
PFZ WorkshopDay Linux - AdvancedPFZ WorkshopDay Linux - Advanced
PFZ WorkshopDay Linux - AdvancedJoshua Thijssen
 
PFZ WorkshopDay Linux - Basic
PFZ WorkshopDay Linux - BasicPFZ WorkshopDay Linux - Basic
PFZ WorkshopDay Linux - BasicJoshua Thijssen
 

More from Joshua Thijssen (14)

Moved 301
Moved 301Moved 301
Moved 301
 
Puppet for dummies - ZendCon 2011 Edition
Puppet for dummies - ZendCon 2011 EditionPuppet for dummies - ZendCon 2011 Edition
Puppet for dummies - ZendCon 2011 Edition
 
Cipher block modes
Cipher block modesCipher block modes
Cipher block modes
 
Puppet for dummies - PHPBenelux UG edition
Puppet for dummies - PHPBenelux UG editionPuppet for dummies - PHPBenelux UG edition
Puppet for dummies - PHPBenelux UG edition
 
15 protips for mysql users pfz
15 protips for mysql users   pfz15 protips for mysql users   pfz
15 protips for mysql users pfz
 
Alice & bob public key cryptography 101 - uncon dpc
Alice & bob  public key cryptography 101 - uncon dpcAlice & bob  public key cryptography 101 - uncon dpc
Alice & bob public key cryptography 101 - uncon dpc
 
Representation state transfer and some other important stuff
Representation state transfer and some other important stuffRepresentation state transfer and some other important stuff
Representation state transfer and some other important stuff
 
Deploying and maintaining your software with RPM/APT
Deploying and maintaining your software with RPM/APTDeploying and maintaining your software with RPM/APT
Deploying and maintaining your software with RPM/APT
 
Alice & bob public key cryptography 101
Alice & bob  public key cryptography 101Alice & bob  public key cryptography 101
Alice & bob public key cryptography 101
 
15 protips for mysql users
15 protips for mysql users15 protips for mysql users
15 protips for mysql users
 
Workshop unittesting
Workshop unittestingWorkshop unittesting
Workshop unittesting
 
Alice & bob public key cryptography 101
Alice & bob  public key cryptography 101Alice & bob  public key cryptography 101
Alice & bob public key cryptography 101
 
PFZ WorkshopDay Linux - Advanced
PFZ WorkshopDay Linux - AdvancedPFZ WorkshopDay Linux - Advanced
PFZ WorkshopDay Linux - Advanced
 
PFZ WorkshopDay Linux - Basic
PFZ WorkshopDay Linux - BasicPFZ WorkshopDay Linux - Basic
PFZ WorkshopDay Linux - Basic
 

Sed & awk the dynamic duo

  • 1. Harness the power of Sed & Awk Everything a PHP developer should know about sed & awk Edition: PHPBenelux, jan 29, 2011, Antwerp http://en.wikipedia.org/wiki/File:Slender_Loris.jpg Sed & Awk - http://joind.in/2489
  • 2. First, who am I? Sed & Awk - http://joind.in/2489
  • 3. First, who am I? Sed & Awk - http://joind.in/2489
  • 4. First, who am I? Joshua Thijssen (32) Sed & Awk - http://joind.in/2489
  • 5. First, who am I? Joshua Thijssen (32) Senior Software Engineer currently working at Enrise (4worx) Sed & Awk - http://joind.in/2489
  • 6. First, who am I? Joshua Thijssen (32) Senior Software Engineer currently working at Enrise (4worx) Development in PHP, Python, Perl, C, java, assembly. Sed & Awk - http://joind.in/2489
  • 7. First, who am I? Joshua Thijssen (32) Senior Software Engineer currently working at Enrise (4worx) Development in PHP, Python, Perl, C, java, assembly. Certified MySQL DBE, MySQL DBA, LPIC-1, LPIC-2, Zend PHP5, Zend PHP5.3, Zend Framework, Ubuntu professional. Sed & Awk - http://joind.in/2489
  • 8. First, who am I? Joshua Thijssen (32) Senior Software Engineer currently working at Enrise (4worx) Development in PHP, Python, Perl, C, java, assembly. Certified MySQL DBE, MySQL DBA, LPIC-1, LPIC-2, Zend PHP5, Zend PHP5.3, Zend Framework, Ubuntu professional. Blogs: http://www.adayinthelifeof.nl Sed & Awk - http://joind.in/2489
  • 9. First, who am I? Joshua Thijssen (32) Senior Software Engineer currently working at Enrise (4worx) Development in PHP, Python, Perl, C, java, assembly. Certified MySQL DBE, MySQL DBA, LPIC-1, LPIC-2, Zend PHP5, Zend PHP5.3, Zend Framework, Ubuntu professional. Blogs: http://www.adayinthelifeof.nl http://www.enrise.com/blog Sed & Awk - http://joind.in/2489
  • 10. First, who am I? Joshua Thijssen (32) Senior Software Engineer currently working at Enrise (4worx) Development in PHP, Python, Perl, C, java, assembly. Certified MySQL DBE, MySQL DBA, LPIC-1, LPIC-2, Zend PHP5, Zend PHP5.3, Zend Framework, Ubuntu professional. Blogs: http://www.adayinthelifeof.nl http://www.enrise.com/blog Email: joshua@enrise.com Sed & Awk - http://joind.in/2489
  • 11. First, who am I? Joshua Thijssen (32) Senior Software Engineer currently working at Enrise (4worx) Development in PHP, Python, Perl, C, java, assembly. Certified MySQL DBE, MySQL DBA, LPIC-1, LPIC-2, Zend PHP5, Zend PHP5.3, Zend Framework, Ubuntu professional. Blogs: http://www.adayinthelifeof.nl http://www.enrise.com/blog Email: joshua@enrise.com Twitter: @jaytaph Sed & Awk - http://joind.in/2489
  • 15. Comfort zones You are a PHP programmer... http://www.gnux-consultant.fr/service/fileadmin/templates/template_fr_1_FILES/elephant-php.gif Sed & Awk - http://joind.in/2489
  • 16. Comfort zones You are a PHP programmer... ...so you program in PHP http://www.gnux-consultant.fr/service/fileadmin/templates/template_fr_1_FILES/elephant-php.gif Sed & Awk - http://joind.in/2489
  • 17. Comfort zones You are a PHP programmer... ...so you program in PHP http://www.gnux-consultant.fr/service/fileadmin/templates/template_fr_1_FILES/elephant-php.gif Sed & Awk - http://joind.in/2489
  • 18. Comfort zones You are a PHP programmer... ...so you program in PHP http://www.gnux-consultant.fr/service/fileadmin/templates/template_fr_1_FILES/elephant-php.gif Sed & Awk - http://joind.in/2489
  • 19. Comfort zones You are doing this already: Sed & Awk - http://joind.in/2489
  • 20. Comfort zones You are doing this already: • SQL (where, order, limit, join) Sed & Awk - http://joind.in/2489
  • 21. Comfort zones You are doing this already: • SQL (where, order, limit, join) • Frameworks (Zend, Symfony, etc) Sed & Awk - http://joind.in/2489
  • 22. Comfort zones You are doing this already: • SQL (where, order, limit, join) • Frameworks (Zend, Symfony, etc) • JQuery, Dojo, etc Sed & Awk - http://joind.in/2489
  • 23. Comfort zones But why learn new stuff when you can do it in PHP? Sed & Awk - http://joind.in/2489
  • 24. Comfort zones But why learn new stuff when you can do it in PHP? ✓ Might be easier to use... Sed & Awk - http://joind.in/2489
  • 25. Comfort zones But why learn new stuff when you can do it in PHP? ✓ Might be easier to use... ✓ Might be faster to write... Sed & Awk - http://joind.in/2489
  • 26. Comfort zones But why learn new stuff when you can do it in PHP? ✓ Might be easier to use... ✓ Might be faster to write... ✓ Might be better suited for the job... Sed & Awk - http://joind.in/2489
  • 27. Comfort zones But why learn new stuff when you can do it in PHP? ✓ Might be easier to use... ✓ Might be faster to write... ✓ Might be better suited for the job... ✓ More efficient Sed & Awk - http://joind.in/2489
  • 28. Comfort zones ! Sed & Awk - http://joind.in/2489
  • 29. Comfort zones I don’t want to tell you HOW to use Sed & Awk. ! Sed & Awk - http://joind.in/2489
  • 30. Comfort zones I don’t want to tell you HOW to use Sed & Awk. I want to tell you that for certain jobs, tools like Sed & Awk are much better suited than PHP. ! Sed & Awk - http://joind.in/2489
  • 31. Comfort zones I don’t want to tell you HOW to use Sed & Awk. I want to tell you that for certain jobs, tools like Sed & Awk are much better suited than PHP. ! Know the capabilities of your tools and you become a better developer... Sed & Awk - http://joind.in/2489
  • 32. Comfort zones Why Sed & Awk? Sed & Awk - http://joind.in/2489
  • 33. Comfort zones Why Sed & Awk? ✓Useful for data manipulation Sed & Awk - http://joind.in/2489
  • 34. Comfort zones Why Sed & Awk? ✓Useful for data manipulation ✓They work well together Sed & Awk - http://joind.in/2489
  • 35. Comfort zones Why Sed & Awk? ✓Useful for data manipulation ✓They work well together ✓Both have a similar processing method Sed & Awk - http://joind.in/2489
  • 36. Comfort zones Why Sed & Awk? ✓Useful for data manipulation ✓They work well together ✓Both have a similar processing method ✓Both rely heavily on regular expressions Sed & Awk - http://joind.in/2489
  • 37. Comfort zones Why Sed & Awk? ✓Useful for data manipulation ✓They work well together ✓Both have a similar processing method ✓Both rely heavily on regular expressions ✓Nobody really harvest their power Sed & Awk - http://joind.in/2489
  • 38. Part I : SED http://www.flickr.com/photos/joachim_s_mueller/4298348196/ Sed & Awk - http://joind.in/2489
  • 39. SED Sed & Awk - http://joind.in/2489
  • 40. SED • is a Stream EDitor Sed & Awk - http://joind.in/2489
  • 41. SED • is a Stream EDitor • applies rules based on a stream of data (per line) Sed & Awk - http://joind.in/2489
  • 42. SED • is a Stream EDitor • applies rules based on a stream of data (per line) • there is no turning back into the stream (going forward only) Sed & Awk - http://joind.in/2489
  • 43. Why use SED? Useful for: Sed & Awk - http://joind.in/2489
  • 44. Why use SED? Useful for: • Changing IP addresses or other data through many files. mutation of large datasets Sed & Awk - http://joind.in/2489
  • 45. Why use SED? Useful for: • Changing IP addresses or other data through many files. mutation of large datasets • complex findin&certain blocks of code/data (for instance, Only change data replace CSV, TXT, SQL files, docblocks etc) Sed & Awk - http://joind.in/2489
  • 46. Why use SED? Useful for: • Changing IP addresses or other data through many files. mutation of large datasets • complex findin&certain blocks of code/data (for instance, Only change data replace CSV, TXT, SQL files, docblocks etc) • complexthe next 10 lines after each 404 code read from an Only print retrieval of data apache log file or print all docblocks and function headers Sed & Awk - http://joind.in/2489
  • 47. When use SED? Use sed when: Don’t use sed when: Sed & Awk - http://joind.in/2489
  • 48. When use SED? Use sed when: • When you need to change hundreds or thousands of files • “Complex” mutations • Fast “one liners” in scripts Don’t use sed when: • When you need to change one or two items • When you need aggregation or variables Sed & Awk - http://joind.in/2489
  • 49. SED Most common example: sed ‘s/foo/bar/g’ old > new changes ‘foo’ into ‘bar’ throughout the file ‘old’ and places output into file ‘new’ Sed & Awk - http://joind.in/2489
  • 50. SED $ cat foo.txt foo bar foo bar foo bar foo bar foo bar bar foo foo foo bar $ sed 's/foo/bar/g' foo.txt bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar Sed & Awk - http://joind.in/2489
  • 51. SED Another common example: sed ‘s/foo//g’ old > new deletes ‘foo’ throughout the file ‘old’ and places output into file ‘new’ Sed & Awk - http://joind.in/2489
  • 52. SED $ cat foo.txt foo bar foo bar foo bar foo bar foo bar bar foo foo foo bar $ sed 's/foo//g' foo.txt bar bar bar bar bar bar bar Sed & Awk - http://joind.in/2489
  • 53. SED A bit more advanced: sed ‘s/foo/FOO/2’ old > new changes the second ‘foo’ on each line into ‘FOO’ Sed & Awk - http://joind.in/2489
  • 54. SED $ cat foo.txt foo bar foo bar foo bar foo bar foo bar bar foo foo foo bar $ sed 's/foo/FOO/2' foo.txt foo bar FOO bar foo bar foo bar FOO bar bar foo foo FOO bar Sed & Awk - http://joind.in/2489
  • 55. SED Sed can use address ranges: sed ‘1,3 s/foo/bar/g’ file changes all ‘foo’s to ‘bar’s on lines 1 to 3 Sed & Awk - http://joind.in/2489
  • 56. SED $ cat foo.txt foo bar foo bar foo bar foo bar foo bar bar foo foo foo bar $ sed '1,3 s/foo/bar/g' foo.txt bar bar bar bar bar bar bar bar bar bar bar foo foo foo bar Sed & Awk - http://joind.in/2489
  • 57. SED But you can also use a regex: sed ‘1,/^$/ s/foo/bar/g’ file changes all ‘foo’s to ‘bar’s on lines 1 to the first empty line Sed & Awk - http://joind.in/2489
  • 58. SED $ cat foo.txt foo bar foo bar foo bar foo bar foo bar bar foo foo foo bar $ sed '1,/^$/ s/foo/bar/g' foo.txt bar bar bar bar bar bar foo bar foo bar bar foo foo foo bar Sed & Awk - http://joind.in/2489
  • 59. SED $ cat foo.txt foo bar foo bar foo bar foo bar foo bar bar foo foo foo bar $ sed '/^$/,$ s/foo/bar/g' foo.txt foo bar foo bar foo bar bar bar bar bar bar bar bar bar bar Sed & Awk - http://joind.in/2489
  • 60. SED A ! negates the address range: sed ‘1,3 ! s/foo/bar/g’ file changes all ‘foo’s to ‘bar’s on every line except lines 1 to 3 Sed & Awk - http://joind.in/2489
  • 61. SED $ cat foo.txt foo bar foo bar foo bar foo bar foo bar bar foo foo foo bar $ sed '1,3 ! s/foo/bar/g' foo.txt foo bar foo bar foo bar foo bar foo bar bar bar bar bar bar Sed & Awk - http://joind.in/2489
  • 62. SED Multiple commands per range: sed ‘1,3 { s/foo/bar/g ; s/.*/Line &/ ; }’ file sed ‘1,3 { s/foo/bar/g s/.*/Line &/ }’ file for line 1 to 3: change foo’s into bar’s and prepend ‘Line’ to the line Sed & Awk - http://joind.in/2489
  • 63. SED $ cat foo.txt foo bar foo bar foo bar foo bar foo bar bar foo foo foo bar $ sed '1,3 { s/foo/bar/g ; s/.*/Line &/ ; }' foo.txt Line bar bar bar Line bar bar bar Line bar bar bar bar bar foo foo foo bar Sed & Awk - http://joind.in/2489
  • 64. SED Multiple ranges: sed ‘1,3 s/foo/bar/g 5,7 s/bar/foo/g s/(.*)/Line 1/’ file on line 1 to 3: change foo’s into bar’s on line 5 to 7: change bar’s into foo’s on all lines: add ‘Line’ in front of the line Sed & Awk - http://joind.in/2489
  • 65. SED $ cat foo.txt foo bar foo bar foo bar foo bar foo bar bar foo foo foo bar $ sed '1,3 s/foo/bar/g ; 5,7 s/bar/foo/g ; s/.*/Line: &/' foo.txt Line: bar bar bar Line: bar bar bar Line: bar bar bar Line: bar bar foo Line: foo foo foo Sed & Awk - http://joind.in/2489
  • 66. SED sed -n ‘ /^cut/ q 1,3 { s/foo/bar/g ; p ; } 4,$ { s/bar/foo/g ; p ; } ’ file -n means ‘don’t print’ lines Sed & Awk - http://joind.in/2489
  • 67. SED sed -n ‘ /^cut/ q 1,3 { s/foo/bar/g ; p ; } 4,$ { s/bar/foo/g ; p ; } ’ file if a line starts with ‘cut’, end processing Sed & Awk - http://joind.in/2489
  • 68. SED sed -n ‘ /^cut/ q 1,3 { s/foo/bar/g ; p ; } 4,$ { s/bar/foo/g ; p ; } ’ file line 1 to 3 will replace ‘foo’ to ‘bar’ and print the line to output Sed & Awk - http://joind.in/2489
  • 69. SED sed -n ‘ /^cut/ q 1,3 { s/foo/bar/g ; p ; } 4,$ { s/bar/foo/g ; p ; } ’ file line 4 to the end will replace ‘bar’ to ‘foo’ and print the line to output Sed & Awk - http://joind.in/2489
  • 70. SED $ cat file.txt foo bar foo bar bar bar foo foo foo bar foo bar bar bar foo foo foo bar foo bar foo bar foo bar bar bar foo foo bar bar foo foo cut this line is not added $ sed -n '/^cut/ q ; 1,3 { s/foo/bar/g ; p ; } ; 4,$ { s/bar/foo/g ; p ; }' file.txt bar bar bar bar bar bar bar bar bar bar bar bar foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo Sed & Awk - http://joind.in/2489
  • 71. SED commands a append ‘text’ to output s substitute data y transform data (like ‘tr’) d delete line (don’t print) n (print) and goto next line N (print) and add next line to pattern space p print pattern space q quit processing r copy contents of file to pattern space # comment = prints current line number Sed & Awk - http://joind.in/2489
  • 72. Commenting out [production] ... bootstrap.path = APPLICATION_PATH "/Bootstrap.php" bootstrap.class = "Bootstrap" resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers" [staging : production] [testing : production] phpSettings.display_startup_errors = 1 phpSettings.display_errors = 1 [development : production] phpSettings.display_startup_errors = 1 ... sed '/^[testing/,/^[/ s/.*/# --- &/' application.ini Sed & Awk - http://joind.in/2489
  • 73. Commenting out sed '/^[testing/,/^[/ s/.*/# --- &/' application.ini [production] ... bootstrap.path = APPLICATION_PATH "/Bootstrap.php" bootstrap.class = "Bootstrap" resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers" [staging : production] # --- [testing : production] # --- phpSettings.display_startup_errors = 1 # --- phpSettings.display_errors = 1 # --- # ---[development : production] phpSettings.display_startup_errors = 1 ... Sed & Awk - http://joind.in/2489
  • 74. Commenting out sed '/^[testing/,/^[/ { /^[/ b /^$/ b s/.*/# --- &/ }' application.ini [production] ... bootstrap.path = APPLICATION_PATH "/Bootstrap.php" bootstrap.class = "Bootstrap" resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers" [staging : production] [testing : production] # --- phpSettings.display_startup_errors = 1 # --- phpSettings.display_errors = 1 [development : production] phpSettings.display_startup_errors = 1 ... Sed & Awk - http://joind.in/2489
  • 75. SED flow control b <label> Unconditionally branch to <label> : <label> Set <label> t <label> Conditionally branch to <label> Sed & Awk - http://joind.in/2489
  • 76. SED flow control solfege.txt sed script do sed ' re :loop mi /$/ N fa s/n */ / so t loop la ' solfege.txt si do Pattern buffer Output Sed & Awk - http://joind.in/2489
  • 77. SED flow control solfege.txt sed script do sed ' re :loop mi /$/ N fa s/n */ / so t loop la ' solfege.txt si do Pattern buffer do Output Sed & Awk - http://joind.in/2489
  • 78. SED flow control solfege.txt sed script do sed ' re :loop mi /$/ N fa s/n */ / so t loop la ' solfege.txt si do Pattern buffer do Output Sed & Awk - http://joind.in/2489
  • 79. SED flow control solfege.txt sed script do sed ' re :loop mi /$/ N fa s/n */ / so t loop la ' solfege.txt si do Pattern buffer do Output Sed & Awk - http://joind.in/2489
  • 80. SED flow control solfege.txt sed script do sed ' re :loop mi /$/ N fa s/n */ / so t loop la ' solfege.txt si do Pattern buffer re Output do Sed & Awk - http://joind.in/2489
  • 81. SED flow control solfege.txt sed script do sed ' re :loop mi /$/ N fa s/n */ / so t loop la ' solfege.txt si do Pattern buffer re Output do Sed & Awk - http://joind.in/2489
  • 82. SED flow control solfege.txt sed script do sed ' re :loop mi /$/ N fa s/n */ / so t loop la ' solfege.txt si do Pattern buffer re mi Output do Sed & Awk - http://joind.in/2489
  • 83. SED flow control solfege.txt sed script do sed ' re :loop mi /$/ N fa s/n */ / so t loop la ' solfege.txt si do Pattern buffer re mi Output do Sed & Awk - http://joind.in/2489
  • 84. SED flow control solfege.txt sed script do sed ' re :loop mi /$/ N fa s/n */ / so t loop la ' solfege.txt si do Pattern buffer re mi Output do Sed & Awk - http://joind.in/2489
  • 85. SED flow control solfege.txt sed script do sed ' re :loop mi /$/ N fa s/n */ / so t loop la ' solfege.txt si do Pattern buffer re mi fa Output do Sed & Awk - http://joind.in/2489
  • 86. SED flow control solfege.txt sed script do sed ' re :loop mi /$/ N fa s/n */ / so t loop la ' solfege.txt si do Pattern buffer re mi fa Output do Sed & Awk - http://joind.in/2489
  • 87. SED flow control solfege.txt sed script do sed ' re :loop mi /$/ N fa s/n */ / so t loop la ' solfege.txt si do Pattern buffer re mi fa Output do Sed & Awk - http://joind.in/2489
  • 88. SED flow control solfege.txt sed script do sed ' re :loop mi /$/ N fa s/n */ / so t loop la ' solfege.txt si do Pattern buffer re mi fa Output do Sed & Awk - http://joind.in/2489
  • 89. SED flow control solfege.txt sed script do sed ' re :loop mi /$/ N fa s/n */ / so t loop la ' solfege.txt si do Pattern buffer re mi fa Output do Sed & Awk - http://joind.in/2489
  • 90. SED flow control solfege.txt sed script do sed ' re :loop mi /$/ N fa s/n */ / so t loop la ' solfege.txt si do Pattern buffer so Output do re mi fa Sed & Awk - http://joind.in/2489
  • 91. Sed not powerful? Delete all lines containing ‘regex’ sed '/regex/d' filename Remove all additional white spaces sed 's/ *$//' filename Reverse all lines in a file (makes use of the hold buffer) sed -n '1 ! G ; h ; $ p' filename Sed & Awk - http://joind.in/2489
  • 92. Sed not powerful? Meet Sedtris: A fully functional Tetris clone written in SED http://uuner.doslash.org/forfun/ Sed & Awk - http://joind.in/2489
  • 93. So use sed when: Sed & Awk - http://joind.in/2489
  • 94. So use sed when: • Repetitive work on many files Sed & Awk - http://joind.in/2489
  • 95. So use sed when: • Repetitive work on many files • “complex” mutations Sed & Awk - http://joind.in/2489
  • 96. So use sed when: • Repetitive work on many files • “complex” mutations • Fast “oneliners” in scripts etc.. Sed & Awk - http://joind.in/2489
  • 97. Part 2 : AWK http://www.flickr.com/photos/joachim_s_mueller/138409464/in/photostream/ Sed & Awk - http://joind.in/2489
  • 98. AWK Sed & Awk - http://joind.in/2489
  • 99. AWK • AWK is a full-fledged programming language. Sed & Awk - http://joind.in/2489
  • 100. AWK • AWK is a full-fledged programming language. • There is NO way I can teach you AWK in +- 20 minutes Sed & Awk - http://joind.in/2489
  • 101. AWK • AWK is a full-fledged programming language. • There is NO way I can teach you AWK in +- 20 minutes • But i’ll try... Sed & Awk - http://joind.in/2489
  • 102. AWK Sed & Awk - http://joind.in/2489
  • 103. AWK • Alfred V. Aho, Peter J.Weinberger, Brain W. Kernighan Sed & Awk - http://joind.in/2489
  • 104. AWK • Alfred V. Aho, Peter J.Weinberger, Brain W. Kernighan • Written in 1977 at AT&T Bell Laboratories Sed & Awk - http://joind.in/2489
  • 105. AWK • Alfred V. Aho, Peter J.Weinberger, Brain W. Kernighan • Written in 1977 at AT&T Bell Laboratories • Multiple versions: AWK, NAWK, GAWK, MAWK and more... Sed & Awk - http://joind.in/2489
  • 106. AWK • Alfred V. Aho, Peter J.Weinberger, Brain W. Kernighan • Written in 1977 at AT&T Bell Laboratories • Multiple versions: AWK, NAWK, GAWK, MAWK and more... • Pattern-directed scanning and processing language... Sed & Awk - http://joind.in/2489
  • 107. AWK Sed & Awk - http://joind.in/2489
  • 108. AWK • [condition] { actions } Sed & Awk - http://joind.in/2489
  • 109. AWK • [condition] { actions } • 2 special “patterns” : BEGIN and END Sed & Awk - http://joind.in/2489
  • 110. Simple AWK $ cat solfege.txt do re mi fa sol la ti do $ awk ' BEGIN { print "start" } /o/ { print "I just saw an o in " $0 } END { print "the end" }' solfege.txt start I just saw an o in do I just saw an o in sol I just saw an o in do the end Sed & Awk - http://joind.in/2489
  • 111. Apache logfile (combined) Awk processes through “records” and “fields” 72.30.161.230 - - [18/Jan/2011:20:28:09 +0100] "GET /robots.txt HTTP/1.0" 200 387 "-" "Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/ slurp)" 72.30.161.230 - - [18/Jan/2011:20:28:10 +0100] "GET / HTTP/1.0" 200 7235 "-" "Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/ slurp)" you can control the record and field separators Sed & Awk - http://joind.in/2489
  • 112. Apache logfile (combined) 72.30.161.230 - - [18/Jan/2011:20:28:09 +0100] "GET /robots.txt HTTP/1.0" 200 387 "-" "Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)" 72.30.161.230 - - [18/Jan/2011:20:28:10 +0100] "GET / HTTP/1.0" 200 7235 "-" "Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)" Field separator “space” Sed & Awk - http://joind.in/2489
  • 113. Apache logfile (combined) 72.30.161.230 - - [18/Jan/2011:20:28:09 +0100] GET /robots.txt HTTP/1.0 200 387 - Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp) 72.30.161.230 - - [18/Jan/2011:20:28:10 +0100] "GET / HTTP/1.0" 200 7235 "-" "Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)" Field separator “double quote” (“) Sed & Awk - http://joind.in/2489
  • 114. Some global AWK knowledge Sed & Awk - http://joind.in/2489
  • 115. Some global AWK knowledge • You can set the field and record separator Sed & Awk - http://joind.in/2489
  • 116. Some global AWK knowledge • You can set the field and record separator • $FS=”|”; $RS=”t” Sed & Awk - http://joind.in/2489
  • 117. Some global AWK knowledge • You can set the field and record separator • $FS=”|”; $RS=”t” • $0 holds the complete record (line) Sed & Awk - http://joind.in/2489
  • 118. Some global AWK knowledge • You can set the field and record separator • $FS=”|”; $RS=”t” • $0 holds the complete record (line) • $1 holds first field, $2 second field etc... Sed & Awk - http://joind.in/2489
  • 119. Some global AWK knowledge • You can set the field and record separator • $FS=”|”; $RS=”t” • $0 holds the complete record (line) • $1 holds first field, $2 second field etc... • $NF holds number of fields in record Sed & Awk - http://joind.in/2489
  • 120. Some global AWK knowledge • You can set the field and record separator • $FS=”|”; $RS=”t” • $0 holds the complete record (line) • $1 holds first field, $2 second field etc... • $NF holds number of fields in record • $NR holds CURRENT record Sed & Awk - http://joind.in/2489
  • 121. Apache logfile (combined) Print the “user agents” from the logfile $ awk -F" '{ print $6 }' apache.log Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp) Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp) Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322) NS8/0.9.6 Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp) Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp) Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322) NS8/0.9.6 Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp) Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp) Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp) Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) Sed & Awk - http://joind.in/2489
  • 122. Apache logfile (combined) Print the “user agents” from the logfile and count them (through external tools) $ awk -F" '{ print $6 }' apache.log | sort | uniq -c 2 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322) NS8/0.9.6 1 Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) 7 Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp) Sed & Awk - http://joind.in/2489
  • 123. Apache logfile (combined) Print the total bytes send out per status code $ awk -F '{ totals[$9] += $10; } END { for (i in totals) { printf "%d : %d bytesn", i, totals[i]; } }' apache.log 200 : 26197250 bytes 206 : 180578 bytes 301 : 31072 bytes 302 : 2991 bytes 304 : 44715 bytes 404 : 82866 bytes 500 : 361783 bytes Sed & Awk - http://joind.in/2489
  • 124. Apache logfile (combined) Print the “user agents” from the logfile who triggered a 4xx code $ awk -F '$9 ~ /4[0-9][0-9]/ { FS="""; $0=$0; print $6; FS=" " }' apache.log Googlebot/2.1 (+http://www.googlebot.com/bot.html) Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 libwww-perl/5.805 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6 Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8b4) Gecko/20050908 Firefox/1.4 Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8b4) Gecko/20050908 Firefox/1.4 Googlebot/2.1 (+http://www.googlebot.com/bot.html) Googlebot/2.1 (+http://www.googlebot.com/bot.html) Googlebot/2.1 (+http://www.googlebot.com/bot.html) Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) Sed & Awk - http://joind.in/2489
  • 125. Apache logfile (combined) Awk one liner compared to PHP: $ awk -F '{ totals[$9] += $10; } END { for (i in totals) { printf "%d : %d bytesn", i, totals[i]; } }' apache.log <?php $hash = array(); foreach( file( './apache.log' ) as $line ) { list( , , , , , , , , $status, $bytes ) = explode( ' ', $line ); if( !isset( $hash[$status] ) ) { $hash[$status] = 0; } $hash[$status] += $bytes; } print_r($hash); Not a whole lot different, but already more complex and this was just a simple example... credits to @RichardJ #pfz channel Sed & Awk - http://joind.in/2489
  • 126. Apache logfile (combined) Sed one liner compared to PHP: sed ‘/^.o/d’ file <?php     $stdin = fopen("php://stdin", "r");     while (!feof($stdin)) {         $line = fgets($stdin);         if (preg_match("/^.o/", $line)) continue;         print $line;     } ?> Much more work.... credits to @RichardJ #pfz channel Sed & Awk - http://joind.in/2489
  • 127. Practical uses for a (PHP) developer • parse php-errors files, syslog files, apache’s http access logs. • Conversion of files you get from your customers, who always assume you can do magic with a gazzillion GB’s of (unsorted) data (and now you can). Sed & Awk - http://joind.in/2489
  • 128. In conclusion: sed & awk Sed & Awk - http://joind.in/2489
  • 129. In conclusion: sed & awk • are powerful for simple one-liners but can also be used for complex programs Sed & Awk - http://joind.in/2489
  • 130. In conclusion: sed & awk • are powerful for simple one-liners but can also be used for complex programs • integrates perfectly with other (unix) tools like uniq, sort, cut, find, grep, cat, etc... Sed & Awk - http://joind.in/2489
  • 131. In conclusion: sed & awk • are powerful for simple one-liners but can also be used for complex programs • integrates perfectly with other (unix) tools like uniq, sort, cut, find, grep, cat, etc... • are a great way to automate complex and/ or repetitive (editing) tasks Sed & Awk - http://joind.in/2489
  • 133. In conclusion • Look outside your comfort zone for other (better) tools. http://files.sharenator.com/slender_loris_Worlds_strangest_looking_animals-s300x451-2279-580.jpg Sed & Awk - http://joind.in/2489
  • 134. In conclusion • Look outside your comfort zone for other (better) tools. • Can you think of examples where you would use Sed or Awk (instead of php?) http://files.sharenator.com/slender_loris_Worlds_strangest_looking_animals-s300x451-2279-580.jpg Sed & Awk - http://joind.in/2489
  • 136. Read more on Sed & Awk Sed: http://www.gnu.org/software/sed/manual/html_node/index.html http://www.grymoire.com/Unix/Sed.html http://www.panix.com/~elflord/unix/sed.html http://www.linuxtopia.org/online_books/linux_tool_guides/the_sed_faq/index.html Awk: http://www.gnu.org/software/gawk/ http://www.grymoire.com/Unix/Awk.html Sed & Awk - http://joind.in/2489
  • 137. Thank you for your attention! Don’t forget to rate my talk on joind.in http://joind.in/2489 http://farm5.static.flickr.com/4078/4790219776_2fe3c9af95_b.jpg Sed & Awk - http://joind.in/2489

Editor's Notes

  1. Welcome sed&amp;awk - quick\nSlender Loris - mascotte from o&amp;#x2019;reilly sed&amp;awk books\n
  2. introduction age, not facebook friends\n
  3. introduction age, not facebook friends\n
  4. introduction age, not facebook friends\n
  5. introduction age, not facebook friends\n
  6. introduction age, not facebook friends\n
  7. introduction age, not facebook friends\n
  8. introduction age, not facebook friends\n
  9. introduction age, not facebook friends\n
  10. introduction age, not facebook friends\n
  11. introduction age, not facebook friends\n
  12. what are comfort zones?\nyou tend to stay inside them\n
  13. everything inside php. \nbut not good for many things: multithreaded, async io\n
  14. everything inside php. \nbut not good for many things: multithreaded, async io\n
  15. everything inside php. \nbut not good for many things: multithreaded, async io\n
  16. everything inside php. \nbut not good for many things: multithreaded, async io\n
  17. everything inside php. \nbut not good for many things: multithreaded, async io\n
  18. everything inside php. \nbut not good for many things: multithreaded, async io\n
  19. everything inside php. \nbut not good for many things: multithreaded, async io\n
  20. everything inside php. \nbut not good for many things: multithreaded, async io\n
  21. everything inside php. \nbut not good for many things: multithreaded, async io\n
  22. everything inside php. \nbut not good for many things: multithreaded, async io\n
  23. everything inside php. \nbut not good for many things: multithreaded, async io\n
  24. everything inside php. \nbut not good for many things: multithreaded, async io\n
  25. everything inside php. \nbut not good for many things: multithreaded, async io\n
  26. everything inside php. \nbut not good for many things: multithreaded, async io\n
  27. everything inside php. \nbut not good for many things: multithreaded, async io\n
  28. everything inside php. \nbut not good for many things: multithreaded, async io\n
  29. everything inside php. \nbut not good for many things: multithreaded, async io\n
  30. everything inside php. \nbut not good for many things: multithreaded, async io\n
  31. everything inside php. \nbut not good for many things: multithreaded, async io\n
  32. everything inside php. \nbut not good for many things: multithreaded, async io\n
  33. everything inside php. \nbut not good for many things: multithreaded, async io\n
  34. everything inside php. \nbut not good for many things: multithreaded, async io\n
  35. everything inside php. \nbut not good for many things: multithreaded, async io\n
  36. everything inside php. \nbut not good for many things: multithreaded, async io\n
  37. everything inside php. \nbut not good for many things: multithreaded, async io\n
  38. everything inside php. \nbut not good for many things: multithreaded, async io\n
  39. everything inside php. \nbut not good for many things: multithreaded, async io\n
  40. everything inside php. \nbut not good for many things: multithreaded, async io\n
  41. everything inside php. \nbut not good for many things: multithreaded, async io\n
  42. everything inside php. \nbut not good for many things: multithreaded, async io\n
  43. everything inside php. \nbut not good for many things: multithreaded, async io\n
  44. everything inside php. \nbut not good for many things: multithreaded, async io\n
  45. everything inside php. \nbut not good for many things: multithreaded, async io\n
  46. everything inside php. \nbut not good for many things: multithreaded, async io\n
  47. everything inside php. \nbut not good for many things: multithreaded, async io\n
  48. everything inside php. \nbut not good for many things: multithreaded, async io\n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. anyone who uses or used sed &amp; awk?\n
  60. anyone who uses or used sed &amp; awk?\n
  61. anyone who uses or used sed &amp; awk?\n
  62. anyone who uses or used sed &amp; awk?\n
  63. anyone who uses or used sed &amp; awk?\n
  64. \n
  65. \n
  66. \n
  67. \n
  68. find&amp;replace IP&amp;#x2019;s during migration trajects\n
  69. find&amp;replace IP&amp;#x2019;s during migration trajects\n
  70. find&amp;replace IP&amp;#x2019;s during migration trajects\n
  71. find&amp;replace IP&amp;#x2019;s during migration trajects\n
  72. find&amp;replace IP&amp;#x2019;s during migration trajects\n
  73. find&amp;replace IP&amp;#x2019;s during migration trajects\n
  74. find&amp;replace IP&amp;#x2019;s during migration trajects\n
  75. find&amp;replace IP&amp;#x2019;s during migration trajects\n
  76. most common example\n
  77. \n
  78. \n
  79. \n
  80. \n
  81. \n
  82. \n
  83. \n
  84. \n
  85. \n
  86. Turn it around: empty line to end of file\n
  87. \n
  88. \n
  89. \\1 is matching pattern\n
  90. \n
  91. on newlines or ;\n
  92. \n
  93. \n
  94. \n
  95. \n
  96. \n
  97. \n
  98. \n
  99. \n
  100. \n
  101. \n
  102. \n
  103. \n
  104. \n
  105. \n
  106. \n
  107. \n
  108. \n
  109. \n
  110. \n
  111. \n
  112. \n
  113. \n
  114. \n
  115. \n
  116. \n
  117. \n
  118. \n
  119. \n
  120. \n
  121. \n
  122. \n
  123. \n
  124. \n
  125. \n
  126. \n
  127. \n
  128. \n
  129. \n
  130. \n
  131. \n
  132. \n
  133. \n
  134. \n
  135. \n
  136. \n
  137. \n
  138. \n
  139. \n
  140. \n
  141. \n
  142. \n
  143. \n
  144. \n
  145. \n
  146. \n
  147. \n
  148. \n
  149. \n
  150. \n
  151. \n
  152. \n
  153. \n
  154. \n
  155. \n
  156. \n
  157. \n