1 and print gives different output in awk why? -


cat file
banana = yellow
strawberry = red

awk -f= '{print $2}' file
yellow
red

awk -f= '{$2}1' file
banana = yellow
strawberry = red

awk -f= '{print $2}' file 

this prints second column of each line of file. in case, print:

 yellow  red 

(note leading whitespace because separator set =).

this:

awk -f= '{$2}1' file 

is same as:

awk -f= '1' file 

because action { $2 } doesn't have effect: doesn't print, doesn't change variable, nothing, evaluates value of $2. it's useless. program equivalent '1' pattern evaluates true. since default action pattern print line, printing file. it's equivalent to:

awk -f= '{ print }' file 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -