awk '{print $9}' the last ls -l column including any spaces in the file name

后端 未结 7 1363
星月不相逢
星月不相逢 2020-12-29 08:13

How would I get awk to output the whole file name in ls -l if some of the files have spaces in them. Usually, I can run this command:



        
7条回答
  •  滥情空心
    2020-12-29 08:18

    There's probably a better approach that involves combining fields somehow, but:

    $ echo 1 2 3 4 5 6 7 8 9 10 11 12 13 14... | 
      awk '{for (i = 9 ; i <= NF ; i++) printf "%s ", $i}'
    9 10 11 12 13 14... 
    

    Using printf "%s " $i will print the i-th field with a space after it, instead of a newline. The for loop just says to go from field 9 to the last field.

提交回复
热议问题