3 ms·
Unfortunately, tac isn't cross-platform. On systems with GNU userland, you can indeed use 'tac', but that isn't available on BSDish systems (including FreeBSD a
by _delirium 12y ago
Unfortunately, tac isn't cross-platform. On systems with GNU userland, you can indeed use 'tac', but that isn't available on BSDish systems (including FreeBSD and Mac OS X), where 'tail -r' is what you want instead. And likewise, 'tail -r' doesn't work on systems with a GNU userland, because the tail in GNU coreutils doesn't implement -r (according to the maintainers, because reversing the order of lines in a file is completely out of scope for what 'tail' is supposed to do). I don't believe anything in POSIX will do this cross-platform in a straightforward way, because neither 'tac' nor the '-r' option of tail are in POSIX. That leaves you with the options: platform-testing if/thens, or rolling your own in an awk/etc. one-liner.
- joeyh 12y agoghc -e 'interact $ unlines . map reverse . lines'
- vertex-four 12y agoOr, on any *nix worth talking about, by default... perl -e 'print reverse <>'
- dbaupp 12y agoIsn't that `rev`, not `tac`? (I think `tac` should be `unlines . reverse . lines`.)
- wyager 12y agoYou are correct. For those not familiar with Haskell, unlines . map reverse . lines is the same thing as (python) lambda data : [line[::-1] for line in data] whereas unlines . reverse. lines is the same as lambda data : [line for line in data][::-1]
- dbaupp 12y agoWell, you need '\n'.join(...) for the "unlines" bit.