如何反转文件中的行顺序? [英] How can I reverse the order of lines in a file?

查看:15
本文介绍了如何反转文件中的行顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想颠倒文本文件(或标准输入)中的行顺序,保留每一行的内容.

I'd like to reverse the order of lines in a text file (or stdin), preserving the contents of each line.

所以,即以:

foo
bar
baz

我想结束

baz
bar
foo

是否有标准的 UNIX 命令行实用程序?

Is there a standard UNIX commandline utility for this?

推荐答案

BSD tail:

tail -r myfile.txt

参考:FreeBSDNetBSDOpenBSDOS X 手册页.

Reference: FreeBSD, NetBSD, OpenBSD and OS X manual pages.

这篇关于如何反转文件中的行顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆