Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Using external variables in awk (See related posts)

See: Accessing external variable in AWK and SED
var="BASH"; echo "unix scripting" | awk '{gsub(/unix/,"'"${var}"'"); print}'
var="BASH"; echo "unix scripting" | awk '{gsub(/unix/,"'"$(echo ${var})"'"); print}'
var="BASH"; echo "unix scripting" | awk -v v="$var" '{sub(/unix/,v); print}'

You need to create an account or log in to post comments to this site.