Tutorial by Examples

The function toupper will convert a string to upper case (capital letters). For example: BEGIN { greeting = "hello" loud_greeting = toupper(greeting) print loud_greeting } This code will output "HELLO" when run.
String concatenation is done simply by writing expressions next to one another without any operator. For example: BEGIN { user = "root" print "Hello "user "!" } will print: Hello root! Note that expressions do not have to be separated by whitespace.
While implementing one of the standard hashing algorithm in awk is probably a tedious task, defining a hash function that can be used as a handle to text documents is much more tractable. A practical situation where such a function is useful is to assign short ids to items given their description, ...
AWK often used for manipulating entire files containing a list of strings. Let's say file awk_test_file.txt contains: First String Second String Third String To convert all the strings to lower case execute: awk '{ print tolower($0) }' awk_test_file.txt This will result: first string se...
SUB function allows to substitute text inside awk sub(regexp, replacement, target) where regexp could be a full regular expression $ cat file AAAAA BBBB CCCC DDDD EEEE FFFF GGGG $ awk '{sub("AAA","XXX", $0); print}' file XXXAA BBBB CCCC DDDD EEEE FFFF GGGG ...
GNU awk supports a sub-string extraction function to return a fixed length character sequence from a main string. The syntax is *substr(string, start [, length ])* where, string is source string and start marks the start of the sub-string position you want the extraction to be done for an optio...

Page 1 of 1