40 likes | 197 Vues
CS311 – Lecture 07 Outline. Worksheet 2 tr – translate and delete gawk – programmable text processing Note: These lecture notes are not intended replace your notes. This is what I expect your notes to already look like, but with more explanation as needed. 1. tr - translate and delete.
E N D
CS311 – Lecture 07 Outline Worksheet 2 tr – translate and delete gawk – programmable text processing Note: These lecture notes are not intended replace your notes. This is what I expect your notes to already look like, but with more explanation as needed. CS311 – Operating Systems 1 1
tr - translate and delete • gets its input through input redirection or pipes. This util doesn't allow a filename. • translate SET1 to SET2 • delete SET1 CS311 – Operating Systems 1 2
gawk - programmable text processing • scans one or more files and perform an action on all of the lines that match a particular condition. gawk [options] [-f fileName] program {variable=value} {fileName} • Lines of the program are of the form:condition {action} • With no condition, the action is performed on every line. • With no action, the lines matching the condition are printed. Conditions are things like: • NR>2 Each line is a "record". NR is the number of this record (line number) • NF>5 Each word is a "field". NF is the number of this fields in this record CS311 – Operating Systems 1 3
gawk - programmable text processing (cont.) • Lines of the program are of the form:condition {action} • Actions look very C like and are things like: • printf $2; Print the second field. • awk '{if($2=="fleece") {printf $3; printf "\n";}}' bbb • Actions are always surrounded in { }'s • awk is an older version of gawk. CS311 – Operating Systems 1 4