This shows you the differences between two versions of the page.
Previous revisionNext revision | |||
— | fuss:awk [2017/02/22 18:30] – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Find Longest Line in a File ====== | ||
+ | |||
+ | <code bash> | ||
+ | awk ' { if ( length > x ) { x = length } }END{ print x }' file.txt | ||
+ | </ | ||
+ | |||
+ | ====== Perform Floating Point Calculations ====== | ||
+ | |||
+ | '' | ||
+ | |||
+ | <code bash> | ||
+ | awk 'BEGIN {printf " | ||
+ | </ | ||
+ | |||
+ | will calculate $\sin(30^\circ)=sin(30rad * \frac{\pi}{180})$ and return: | ||
+ | |||
+ | < | ||
+ | 0.500 | ||
+ | </ | ||
+ | |||
+ | Since '' | ||
+ | |||
+ | ====== Delimiter-Style ====== | ||
+ | |||
+ | Suppose you have a file '' | ||
+ | < | ||
+ | variable = value | ||
+ | </ | ||
+ | or: | ||
+ | < | ||
+ | variable = value | ||
+ | </ | ||
+ | |||
+ | The following command can be used to obtain '' | ||
+ | <code bash> | ||
+ | awk -F"[ \t]*[=][ \t]*" '{ print $2 }' input | ||
+ | </ | ||
+ | |||
+ | ====== Remove Duplicate Entries in File Without Sorting ====== | ||
+ | |||
+ | To remove all duplicates from '' | ||
+ | <code bash> | ||
+ | awk ' | ||
+ | </ | ||
+ | |||