Skip to Content
gnux

tacx

Concatenate and print files in reverse.

Mirrors GNU tac. Run it as tacx, or as gnux tacx.

Synopsis

tacx [OPTION]... [FILE]...

GNU reference

Description

tacx writes each FILE to standard output last line first. With no FILE, or when FILE is -, it reads standard input. Each FILE is reversed on its own, and the files are written in the order given. A record ends with its separator, a newline by default, so a last line without one is joined to the line before it in the output, as in GNU. -s STRING uses STRING as the separator instead, and -b attaches the separator to the start of the record that follows it rather than to the end of the one before. -r treats the separator as a regular expression; gnux uses Go's RE2 syntax (close to POSIX extended regular expressions) rather than the GNU regex dialect, and reports an invalid expression in Go's words. Each input is read whole into memory before it is written.

Permissions

Needs read permission on each FILE and search permission on the directories leading to it. Nothing is ever modified.

Use cases

  • Reading a log newest entry first.
  • Reversing the order of a list or a history file.
  • Processing records last to first, such as undoing steps in reverse.
  • Reversing records separated by something other than a newline with -s.
  • Finding the last match in a file by reversing it before searching.

Flags

  -b, --before             attach the separator before instead of after
      --help               display this help and exit
  -r, --regex              interpret the separator as a regular expression
  -s, --separator STRING   use STRING as the separator instead of newline
      --version            output version information and exit

Examples

Read a log newest entry first

tacx app.log

See the ten most recent log entries, newest at the top

tacx app.log | headx

Count down instead of up

seqx 5 | tacx

Reverse two logs, each kept separate

tacx a.txt b.txt

Reverse items in a comma-separated list

printfx 'a,b,c,' | tacx -s ,

Reverse sections of a file that each start with a '---' line

tacx -b -s '---' notes.txt

Reverse records separated by numbers of any length

tacx -r -s '[0-9]+' data.txt

Keep a newest-first copy of a history file

tacx history.txt > reversed.txt

Get the order to undo a list of setup steps

tacx steps.txt | catx -n

Sort a list descending without a second sort

sortx names.txt | tacx

Show the five newest log lines in the portable gnux shell

gnux shell -c 'tacx app.log | headx -n 5'

Options

Each option has a page of its own, with its usage and examples.

Exit status

StatusMeaning
0success: every operand was processed
1failure: an operand could not be processed (diagnosed on standard error), or a command-line mistake

Help in the terminal

tacx --help                # options, first examples, exit status
gnux help tacx             # this page: the full manual
gnux help tacx --OPTION    # one option in depth, with its examples

See also

On this page