1. Substitute all
s/foo/bar/g replaces every occurrence of foo with bar on each line; the trailing g makes it global.
sed 's/foo/bar/g' file.txtTyporithm · hard
Step 1 of 8 · intro card
Text Processing
sed is a stream editor: s/old/new/g substitutes all matches per line, and -n with p prints only selected lines or ranges. awk processes records by field — $1 is the first field, -F sets the delimiter, and a pattern like $3 > 100 guards the action.
sed edits a text stream line by line. Its workhorse is substitution: sed 's/foo/bar/g' file.txt replaces every foo with bar, where the trailing g makes the change global instead of first-match-only.
By default sed prints every line. Pairing -n (suppress output) with the p command prints only what you ask for, so sed -n '1,5p' file.txt emits just lines 1 through 5.
awk reads each line as a record split into fields. $1, $2, ... reference fields, -F sets the delimiter (here a comma for CSV), and a leading pattern such as $3 > 100 guards the { } action so it runs only on matching records.
sed s/old/new/g substitutes every match on a line.
sed -n '1,5p' prints only the selected line range.
awk fields are $1, $2, ...; -F sets the delimiter; a pattern guards the action.
sed 's/foo/bar/g' file.txt
sed -n '1,5p' file.txt
awk '{print $1}' access.log
awk -F, '{print $2}' data.csv
awk '$3 > 100 {print $1}' data.txtConnect each part of the code to the concept before you type.
s/foo/bar/g replaces every occurrence of foo with bar on each line; the trailing g makes it global.
sed 's/foo/bar/g' file.txt-n suppresses the default output and p prints only lines 1 through 5.
sed -n '1,5p' file.txtawk splits each line into fields; $1 is the first field, printed for every record.
awk '{print $1}' access.log-F, sets the field separator to a comma, so $2 is the second CSV column.
awk -F, '{print $2}' data.csvThe pattern $3 > 100 runs the action only on records whose third field exceeds 100.
awk '$3 > 100 {print $1}' data.txtRead the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.