« Back to Index

Awk insert before and after regex match

View original Gist on GitHub

Awk insert before and after regex match.sh

echo -e "foo\nbar\nbaz" | awk '/bar/ && found == 0 {found = 1; print "---"; print; print "---"} {print}'

# foo
# ---
# bar
# ---
# bar
# baz