带有空格的文件名的awk或cut字段

时间:2016-08-26 09:50:00

标签: awk cut

从下面

-rw-r--r-- 1 user user 0 Aug 26 15:20 /home/user/public_html/this\ space.ext

我想提取最后一栏。预期产量:     / home / user / public_html / this \ space.ext

我尝试过切割:

ls -lh  /home/user/public_html/this\ space.ext | cut -d ' ' -f9

输出:

/home/user/public_html/this\

我尝试使用awk:     ls -lh / home / user / public_html / this \ space.ext | awk' {print $ 9}'

输出:

/home/user/public_html/this\

1 个答案:

答案 0 :(得分:1)

awk

$ echo "-rw-r--r-- 1 user user 0 Aug 26 15:20 /home/user/public_html/this\ space.ext" | 
  awk -F'[^\\\\] ' '{print $NF}'

/home/user/public_html/this\ space.ext

在非反斜杠char之后将分隔符定义为空格。

相关问题