Regex, Grep, Awk, Sed
Regex, Grep, Awk, Sed
Objectives
– REGEX
– grep
– sed
– awk
REGEX - Regular Expression
• syntax:
• 4d : delete line 4
• syntax:
concepts:
– Fields:
• The fields are denoted $1, $2, ..., while $0 refers to• A pattern-action statement has the form: • A missing
{action} means print the line • A missing pattern always matches. the entire line.
• If FS is null, the input line is split into one field per character.
– Records:
pattern {action}
Pattern-action statements are separated by newlines or semicolons. There are three separate action blocks:
BEGIN {action}
{action}
END {action}
Simple awk example
awk - built in variables
The awk program has some internal environment variables that are
(default whitespace)
the following:
• Using variables:
– You can use the stock $1, $2, $3, … fields and set them to
variables in the action
block.
awk - variables - example
sed vs awk vs grep
Conclusion