Weird awk behaviour , $1 is printed but $0 is not?

Viewed 944

This is printed fine ls | xargs -I var sh -c 'echo var | awk "{print $1}"'

while this is not ls | xargs -I var sh -c 'echo var | awk "{print $0}"'

Obviously this is not my use case and is just to reproduce the problem.

So while $0 stands for complete line, it is weird for $0 to not print while $1 gets printed.

Reference OS - Ubuntu 14.04

2 Answers

For others landing here: If your syntax was perfect but you are potentially using windows files, remember the \r will effectively overwrite your text and make it seem like $0 is blank....

First run dos2unix <file>, then try your awk.

Note: removing \r with sed or tr isn't enough

Related