Presentation is loading. Please wait.

Presentation is loading. Please wait.

LING 408/508: Computational Techniques for Linguists

Similar presentations


Presentation on theme: "LING 408/508: Computational Techniques for Linguists"— Presentation transcript:

1 LING 408/508: Computational Techniques for Linguists
Lecture 12

2 Today's Topics Continuing with gawk regexs: Homework 5
Homework 5

3 awk: regex

4 awk: gensub gensub(regexp, replacement, how [, target])  Search the target string target for matches of the regular expression regexp. If how is a string beginning with ‘g’ or ‘G’ (short for “global”), then replace all matches of regexp with replacement. Otherwise, how is treated as a number indicating which match of regexp to replace. If no target is supplied, use $0. It returns the modified string as the result of the function and the original target string is not changed. gensub() provides an additional feature that is not available in sub() or gsub(): the ability to specify components of a regexp in the replacement text. This is done by using parentheses in the regexp to mark the components and then specifying ‘\N’ in the replacement text, where Nis a digit from 1 to 9. 

5 awk: gensub If only a BEGIN section, no need to provide file (to read). gawk 'BEGIN {print "hello"}' hello -v (sets variable): gawk -v n="hello" 'BEGIN {print n, "\n"}' hello  gensub(regex, replacement,how, target) regex = /(.+) (.+)/ replacement = "\\2 \\1" how = "g" target = (variable) n gawk -v n="hello goodbye" 'BEGIN {print gensub(/(.+) (.+)/, "\\2 \\1", "g", n), "\n"}' What happens?

6 Homework 5 Reference: Answer questions 1,2 and 4 using file hw5data.txt Extra credit! supply your own hw5q5data.txt hw5a6data.txt test files

7 Homework 5 File: hw5data.txt there's one line per question
line 3 is left intentionally blank

8 Homework 5 Question 1: fix this code! Line 1 of hw5.data:

9 Homework 5 Show your awk command line Due next Monday by midnight
Subject: 408/508 Homework 5 Your Name One PDF file please!


Download ppt "LING 408/508: Computational Techniques for Linguists"

Similar presentations


Ads by Google