This is an old revision of the document!


Find Longest Line in a File

awk ' { if ( length > x ) { x = length } }END{ print x }' file.txt

Perform Floating Point Calculations

awk can be used for complex calculations, for example:

awk 'BEGIN {printf "%.3f\n", sin(30 * atan2(0, -1)/180)}'

will calculate $\sin(30^\circ)=sin(30rad * \frac{\pi}{180})$ and return:

0.500

Since awk does not have a constant for $\pi$, we use atan2(0, -1) instead.

Delimiter-Style

Suppose you have a file input containing data separated by delimiters such as:

variable = value

or:

variable = value

The following command can be used to obtain value:

awk -F"[ \t]*[=][ \t]*" '{ print $2 }' input

Remove Duplicate Entries in File Without Sorting

To remove all duplicates from file.txt without sorting, issue:

awk '!x[$0]++' file.txt

fuss/awk.1487788235.txt.gz ยท Last modified: 2017/02/22 18:30 by 127.0.0.1

Wizardry and Steamworks

© 2025 Wizardry and Steamworks

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.