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

后端 未结 7 1291
星月不相逢
星月不相逢 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:23

    A solution is to encode & decode the space with a word or character by using sed:

    ls -l | sed s/\ /{space}/ | awk '{print $9}' | sed s/{space}/\ /
    

    This will replace all spaces in a line with {space} before passing it to awk. After the line has passed to awk, we replace {space} back with space.

    find as stated by others is a much better solution. But if you really have to use awk, you can try this.

提交回复
热议问题