专注各种脚本编程
Baidu
加入收藏夹
本站内容有下面分类知识,欢迎您的到来^_^
shell相关:指令篇 基础篇 脚本欣赏 编程实例 shell问问 shell视频教程 技巧篇 水平测试 E文资料 vi编辑器 高级Bash脚本编程指南
其他:mysql perl c语言 oracle
当前位置:| 主页>shell基础篇>

使用 tac 命令逆序排序文件

百度收藏 QQ搜藏

如果您想对文件中的各行进行逆序排序,该怎么做呢?这就要用到 tac 命令。(请注意,tac 由 cat 逆序拼写而成。)该命令对所列出的文件中的各行或各段进行逆序排序。

该命令不能逆序排序各文件的顺序 — 这个任务您得自己做,以逆向顺序在 tac 命令后列出各文件即可。作为说明 tac 的工作原理的示例,对一些文件使用 ls -l | tail 和 ls -l | tail | tac,比较其结果。

[sam@chenwy split]$ ls -l |tail
总用量 32
-rw-r--r--    1 sam      sam          1649 12月  4 11:13 passwd
-rw-rw-r--    1 sam      sam            84 12月  4 11:19 split1
-rw-rw-r--    1 sam      sam            14 12月  4 11:25 xaa
-rw-rw-r--    1 sam      sam            14 12月  4 11:25 xab
-rw-rw-r--    1 sam      sam            14 12月  4 11:25 xac
-rw-rw-r--    1 sam      sam            14 12月  4 11:25 xad
-rw-rw-r--    1 sam      sam            14 12月  4 11:25 xae
-rw-rw-r--    1 sam      sam            14 12月  4 11:25 xaf
正序

[sam@chenwy split]$ ls -l |tail | tac
-rw-rw-r--    1 sam      sam            14 12月  4 11:25 xaf
-rw-rw-r--    1 sam      sam            14 12月  4 11:25 xae
-rw-rw-r--    1 sam      sam            14 12月  4 11:25 xad
-rw-rw-r--    1 sam      sam            14 12月  4 11:25 xac
-rw-rw-r--    1 sam      sam            14 12月  4 11:25 xab
-rw-rw-r--    1 sam      sam            14 12月  4 11:25 xaa
-rw-rw-r--    1 sam      sam            84 12月  4 11:19 split1
-rw-r--r--    1 sam      sam          1649 12月  4 11:13 passwd
倒序

[sam@chenwy split]$ tac split1
this is line6
this is line5
this is line4
this is line3
this is line2
this is line1
对文件操作

上一篇:使用head和tail以块方式读取文本流 下一篇:Shell简介第一篇:超级工具/Terminals,xterms 和 Shells

power by soyo123 2007-2008