Is there any way for listing file contents in a shell window, such that characters are printed from right to left rather than as usual from the left to the right? or such that the BIDI algorithm steers line direction as per the text present?
This is relevant when working with text files belonging to RTL languages (as well as mixed LTR RTL documents) where you want to grep and search a lot without loading into an editor… editors don't like huge files…
Something around cat
could be nice 🙂
In fact maybe I'll write something that just reverses each line and pipes to cat
if nothing known exists.
Best Answer
The command you need is
rev
, e.g.:Of course this also works with files:
rev filename
instead ofrev <filename
is possible but not preferable, as Stéphane Chazelas explains.As part of
util-linux
rev
is installed on every Ubuntu system by default.This and alternative approaches can be found on HowTo: Reverse a String In Unix / Linux Shell? · nixCraft.
By the way:
rev
is toecho
liketac
is tocat
, so to reverse the order of lines in a file: