Dereferencing variables in awk -


why doesn't work?

x=5 $ ls -l | awk '{print $(($x))}' 

should print field 5 of ls -l command, right?

the ways should pass in value of shell variable awk following

$ x=5  $ ls -l | awk -v x="$x" '{print $x}'  $ ls -l | awk '{print $x}' x="$x" 

the main difference between these 2 methods using -v value of x set in begin block whilst second method value not set. other methods quoting tricks or escaping should not used unless headaches.


however don't want being parsing ls @ all, command want is:

stat --printf="%s\n" * 

assuming fifth column of ls same mine, display file sizes in current directory.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -