on the prompt:ls | awk '{printf(%s\t\t%s\n, $9, $3);}'succeeds in printing what it is supposed to be printing. If I put it in a file, I get four or five empty lines (about the number of lines in the output of ls):$ cat awk-file-owner-simple #!/bin/bashls | awk '{printf(%s\t\t%s\n, $9, $3);}'$ ./awk-file-owner-simple ____Where _ stand for empty lines (that can't be displayed using the code formatter of stackexchange).
why does `awk` fail when I put it in a bash script
bash;awk
Change ls | to ls -l |.You have evidently aliased ls to ls -l in your shell (possibly a function and/or other options); use type ls to see what you're actually executing. Scripts don't get aliases, so it's just running the normal ls, with its single column of output.