shell - Ubuntu linux命令提取子字符串里面

标签 shell ubuntu

我在 ubuntu 上有一个 txt 文件,其中包含

-rw-r--r-- 1 ftp ftp 0 Feb 26 11:37 6.txt
-rw-r--r-- 1 ftp ftp 0 Feb 26 11:37 7.txt
-rw-r--r-- 1 ftp ftp 0 Feb 26 11:37 8.txt

我可以只想检索文件名吗

6.txt
7.txt
8.txt

到另一个文本文件

最佳答案

awk '{print $NF}' your_file >only_names.txt

或者
perl -lane '{print $F[scalar(@F)-1]}' your_file >only_names.txt

如果要更改现有文件:
perl -i -lane '{print $F[scalar(@F)-1]}' your_file

关于shell - Ubuntu linux命令提取子字符串里面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15082778/

相关文章:

bash - bash中的多个/划分列

linux - 如何递归地 curl 所有文件

python - Scapy 模块阻止 PyCharm 调试器

php - Xdebug 已安装,但未显示在 phpinfo 上

python - 查找文件中存储的时间值之间的差异平均值

shell - cron 无法在 shell 脚本中使用 hadoop 命令

linux - kubectl topnodes命令只给出CPU和内存使用情况,如何获取Kubernetes集群中的GPU使用信息?

bash - 如何在跳过一些文件和目录的同时移动文件

linux - 如何正确杀死 child_process ?

opengl - Xlib:显示 "GLX"上缺少扩展 ":0"