Regular Expressions
You can search using regular expressions. Regular Expression support includes, among other things, the plus sign(+), which means “one or more of the preceding character or set of characters and the use of a pipe(|) to mean “OR”.
Examples:
- /Bozo/ { print $0; total = total + 1 }
- Print lines that have the pattern “Bozo” and count them.
- /10+9/ { print $0 }
- Print the line if you have a pattern of a “1”, followed by one or more “0”, followed by a “9”.
- See awk_prog2a and awk_prog2b. (Use awk_data2)
Doing Something Once
- You can use “BEGIN” to denote a block at the beginning of your program that you want to have execute only once at the start of your program.
- You can use “END” to denote a block at the end of your program that you want to have run once, at the end.
- You can have at most one “BEGIN” and one “END”. You do not have to have both if you only need one.
- Examples: awk_prog7a, awk_prog7b and awk_prog7c which use awk_data7. awk_prog7d which uses awk_data7d.