$ awk '{print}/baz/ {sub("baz", "elephant"); print}' jvns.txt
foo:
- bar
- baz
- elephant
- bananas
Since the script is single quoted you can also lay it out legibly: $awk '
{print}
/baz/ {
sub ("baz", "elephant")
print
}
'
which is nice for more complex "one liners".
Awk is also standard on all posix environments and in the mawk flavor is extremely fast (relevant if you are processing huge files).There is superb book, The AWK Programming Language, which teaches a lot about programming in addition to the awk language. Good discussion and link to pdf here: [0]