감동, 마음이 움직이는 것

[linux] awk 본문

Tips (Utility, Computer Language, and etc.)

[linux] awk

Struggler J. 2016. 9. 19. 17:17

How to use "awk" (it is really cool!)


1. When you want to make a new file from data file with several fields:

awk '{print $1, $3}' simulation.d > total.d


2. If you want to extract certain conditioned field:

awk '$1>100 && $1<1 {print $0}' total.d > data.d


3. When you want to sum up the elements in the column:

awk 'x+=$2 {print x}' data.d


4. line number: you can print line number "NR"

awk '{print NR $2}' data.d