How Do I Reverse a File in Unix?
Contents

How do you reverse a line in a file?

The idea is to do the following:

  1. For each line move it to line 1 (to reverse). Command is g/^/m0 . …
  2. Print everything. Command is %p . …
  3. Forcefully quit without saving the file. Command is q! .

What command prints file in reverse?

Print File in Reverse Using Unix Command

  1. The tac command in unix can be used to print the file in reverse. The tac command is. tac file.txt.
  2. The sed command for reversing the lines in a file is. sed ‘1! G;h;$!d’ file.txt.
  3. Another usage of sed command is.
Sophia Al-Mansoor

Sophia Al-Mansoor

Global Business & E-Commerce Reporter

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.

Share this article
Twitter Facebook Pinterest