【发布时间】:2014-04-23 23:32:27
【问题描述】:
我有一个脚本,它使用cut 从包含绝对路径的搜索中挑选一些信息。它看起来像:
PLACE=$(grep foo flatfile.txt | cut -d '/' -f 1-6)
输出如下:
machine1:/path/to/where/foo/is
machine2:/another/path/to/find/foo
我需要它看起来像这样:
machine1:/path/to/where/foo/is/
machine2:/another/path/to/find/foo/
这需要在脚本末尾使用echo "$PLACE" 或类似的东西打印到控制台。输出将始终至少为 2 行,但通常更多。
我尝试了所有我能想到的 echo,但它要么根本不显示输出,要么给出输出:
grep: '/' is a directory
我在 Solaris 上运行 bash 3.00,如果有帮助的话。我真的很想亲吻这只需在 cut 命令的末尾添加一些东西,而不必使用 sed 或 awk 进行猴子。但是,如果这是唯一的方法,那就这样吧。
【问题讨论】: