Csc 4630
Download
1 / 9

CSC 4630 - PowerPoint PPT Presentation


  • 103 Views
  • Uploaded on

CSC 4630. Meeting 12 Exam Reprise. Regular Expressions. In awk distinguish among /[a-dw-z]/ /^[a-dw-z]/ /[^a-dw-z]/ /^[a-dw-z]$/ !/[a-dw-z]/. Variables in Scripts. Built-in vs. user defined Initialization conventions Values vs. names Types and coercion. awk Variables. Compare NF

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' CSC 4630' - taniel


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Csc 4630

CSC 4630

Meeting 12

Exam Reprise


Regular expressions
Regular Expressions

In awk distinguish among

  • /[a-dw-z]/

  • /^[a-dw-z]/

  • /[^a-dw-z]/

  • /^[a-dw-z]$/

  • !/[a-dw-z]/


Variables in scripts
Variables in Scripts

  • Built-in vs. user defined

  • Initialization conventions

  • Values vs. names

  • Types and coercion


Awk variables
awk Variables

  • Compare

    • NF

    • $NF

    • NR

    • $NR


Awk variables 2
awk Variables (2)

Example: Implement wc for numnames

{len += length($1)}

END {print NR, NR, NR + len}

Notes:

  • len initializes to 0

  • NR increments with each line read

  • NF is consistently 1

  • length($0) = length($1) = length($NF)

  • length does not count the \n line terminators


Awk strings
awk Strings

Suppose each line of a file looks like the 14

character string

(610) 519-4505

How many fields are there in the string?

  • If using default FS, two fields, lengths 5,8

  • If FS = “-”, two fields, lengths 9,4


Awk strings 2
awk Strings (2)

Reformatting the string (610) 519-4505 and others of this form

{print substr($1,2,3) “-” $2}

Notes:

  • No pattern means apply to all lines

  • No commas in print statement means concatenate strings, commas mean insert OFS

  • awk does not allow multiple simultaneous field separators (except the default space and tab


Awk scripts
awk Scripts

Given data separated by tabs, fifth field is elapsed time given as hh:mm

Script computes average elapsed time.

Try again (by Wednesday), using a template that

  • has one action statement in body

  • has one calculation and one print statement for the END pattern

  • uses one user-defined variable called t

  • uses + * / % operators, int and substr functions


Awk scripts 2
awk Scripts (2)

Given a file of words, one per line.

Script returns frequency count of the letters in the words.

Try again (by Wednesday), using a template that

  • has one action statement in body, a for loop

  • has one statement for the END pattern, a for loop that controls the printing

  • uses one user-defined variable, an array called lc


ad