linux - 使用 cut 或 awk 操作目录?

标签 linux bash command-line awk command

我正在 Linux 中处理一些目录,我正在尝试操作文件名,这是我的例子

grep 'string' | awk '{print $2$3}' 

我得到以下信息

dir1/another-directory/even-another-directory/file1.jpeg
dir1/another-directory/even-another-directory/fiiile2.jpeg
dir1/another-directory/even-another-directory/filee4.jpeg
dir1/another-directory/even-another-directory/fileee1.jpeg

我正在尝试获取这些文件的最后一部分(斜线后的任何内容),以便我得到这样的列表,也许是 CSV 文件?

file1.jpeg
fiiile2.jpeg
filee4.jpeg
fileee1.jpeg

awk 或 cut 能做到吗?我知道这是一个非常基本的问题,但到目前为止我在网上找不到相关的东西。

谢谢,

最佳答案

用 awk 做所有事情:

awk '/string/{x=$2$3;sub(/.*\//,"",x);print x}'

关于linux - 使用 cut 或 awk 操作目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16855631/

相关文章:

linux - 在没有 super 用户的情况下配置 apache

bash - 通过终端向另一个登录用户发送消息 BASH 编程

java - 从命令行运行 jar 时覆盖 pom.xml 中指定的主类

c# - 如何在远程服务器上运行命令行程序

linux - 使用变量替换为 sed 并添加

c - 鼠标指针在输入子系统中移动后无法模拟 Click 事件

mysql - 从 bash 脚本运行 "mysql"命令

linux - ssh 密码

windows - powershell 2.0重定向文件句柄异常

c - 加载内核模块时出现未知符号