Linux Command

awk

Posted by Dingding on September 25, 2017

引用自:三十分钟学会AWK

awk

pattern scanning and text processing language

工作流程

st=>start: Excute AWK commands from BEGIN block
e=>end: Excute AWK commands from END block

read=>operation: Read a line from input stream
execute=>operation: Execute AWK commands on a line
cond=>condition: Is it End of File

st->read->execute->cond
cond(yes)->e
cond(no,right)->read

程序框架 注意:BEGIN/End是awk的关键字,必须大写

BEGIN {awk-commands}

/pattern/ {awk-commands}

END {awk-commands}

awk example

将最后一列的日期型字符串转为时间戳

#!/bin/bash
awk '{
	for (i=1;i<NF;i++){
		printf $i "\t";
	}
	cmd=("date +%Y-%m-%d-%H -d @" $NF);
	system(cmd);
	printf("\n"); 
}' $1;