linux_wiki:awk

This is an old revision of the document!


Awk

General Information

AWK is a pattern scanning and processing language. Gawk is the GNU Project's implementation of the AWK programming language.

I typically stick to using gawk and in most cases, awk is a symlink to gawk. This page will contain useful gawk commands as I run into them.

Checklist

  • Distros: All
  • gawk installed

gawk's gsub string function matches and replaces regular expressions. This can replace a grep | sed combination.

~$ echo -e "Hello, friend.\nHello, how are you?\nI am fine." | gawk 'gsub(/Hello/,"Goodbye")'
Goodbye, friend.
Goodbye, how are you?

Notice that the last line “I am fine.” is not displayed at all because it doesn't match the regex. (Hello)

  • linux_wiki/awk.1425956008.txt.gz
  • Last modified: 2019/05/25 23:50
  • (external edit)