Newbie awk usage example

I just started using awk for pulling data out of a flatfile. The $\$$number values (e.g. $\$$1) represent columns (e.g. $\$$1 is column 1) of a tab separated value file (designated with the -F'\t' option). Here, awk is receiving lines piped to it from head, and outputting information for rows in which column 14 is equal to 4.
#Test of using Aho, Weinberger, and Kernighan.

#Statements (i.e. print statements) can be put in the brackets for Begin and End for execution.
head -n 50 LeafAngle_BTx6230-IS3620C_Field_06-13-13.csv | awk -F'\t' '\
BEGIN { print "Plant\tRep\tLeaf4_Area\tLeaf4_Max_Width\tLeaf4_Average_Width\tLeaf4_Length" } \
$14=="4" { print $12"\t"$13"\t"$15"\t"$17"\t"$18"\t"$19 } \
END { } \ 
'
And for use without head:
#Test of using Aho, Weinberger, and Kernighan.

#Statements (i.e. print statements) can be put in the brackets for Begin and End for execution.
awk -F'\t' '\
BEGIN { print "Plant\tRep\tLeaf4_Area\tLeaf4_Max_Width\tLeaf4_Average_Width\tLeaf4_Length" } \
$14=="4" { print $12"\t"$13"\t"$15"\t"$17"\t"$18"\t"$19 } \
END { } \ 
' LeafAngle_BTx6230-IS3620C_Field_06-13-13.csv > Leaf_4_out.tsv

Comments

Popular Posts