Linux/Basic commands/awk

From Wikiversity
Jump to navigation Jump to search

AWK is a language/utility designed and used mainly for text processing.


Basic Examples[edit]

  • Prepend a variable string ($STRING_TO_PREPEND) at the beginning of every line
cat file.txt | awk '{print "'$STRING_TO_PREPEND' "$0}'[1]

In case text to prepend is a variable ($PREPEND_TEXT_VAR):

echo "$ORIGINAL_TEXT" | awk -v AWK_PREPEND_VAR="$PREPEND_TEXT_VAR" '{print AWK_PREPEND_VAR" "$0}'

See also[edit]

  • https://serverfault.com/questions/72744/command-to-prepend-string-to-each-line