Awk

  • What is Awk?
    • A basic scripting language that can be used on the command prompt or in an actual awk script
    • Awk can support one line programs and is considered turing complete
    • Awk can do regular expressions
  • What is Awk good at?
    • Data manipulation
    • Filtering out information to match a pattern
    • Getting a report of information from a file
    • String manipulations such as printing parts of strings
  • What is Awk not so good at?
    • Speed/efficiency awk scans line by line so it's not going to enjoy millions of lines, and is not a replacement for things like SQL
    • Complex programs and GUIs
  • Some examples of how to use awk as shown in the video
    • Let's say we want to change how a file is being formatted we could do things like this:
      • awk '{print $1}' filename
      • awk '{print $1 "\t" $5}' filename
    • Let's say we want to use awk for pattern matching
      • To search for MA: awk '/MA/ {print $2 "\t" $5}' filename
    • We can also play with delimiters in multiple ways
      • awk -F: '/MA/ {print $1 "\t" $2}' filename
      • awk -v FS=: '/MA/ {print $1 "\t" $2}' filename
      • awk '/MA/ {print $1 "\t" $2}' FS=: filename
      • awk 'BEGIN{FS=":"} /MA/ {print $1 "\t" $2}' datebook
  • Some Awk Resources

Suggested Activities and Exercises:

  • Download the AwkLab File by right clicking Here and saving your file onto your Linux machine, and then Complete the problem sets that are found on This PDF using the awklab.data file you downloaded from above. Make sure you are paying attention to file location and your paths
  • Here is another video on how to use awk

Would you like to see some more classes? Click here