Linux tac command implementation example

Linux tac command implementation example

1. Command Introduction

The tac (reverse order of cat) command outputs the file contents in reverse order in lines, that is, the first line is displayed last and the last line is displayed first. The output is the opposite of the cat command.

2. Command format

tac [OPTION]... [FILE]...

If no file is given or file is -, standard input is read.

3. Option Description

Mandatory arguments for long options are mandatory for short options as well.

-b, --before
 Add separators at the beginning of the line instead of at the end -r, --regex
 Treat separator as a regular expression to parse -s, --separator=STRING
  Specify a string to replace the newline character as a line separator --help
 Display this help message and exit --version
 Display version information and exit

4. Common Examples

Given files file1 and file2 for testing, the contents are:
file1 content:

123
456
789

file2 content:

abc
def

(1) View the file contents in reverse order.

tac file1
789
456
123
 

(2) View the file contents in reverse order, using string b as the line separator.

tac -s "b" file2
c
def
ab

(3) Connect files file1 and file2 to file3.

tac file1 file2 > file3

cat file3
789
456
123
def
abc

References
[1] tac(1) manual

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • One shell command a day Linux text operation series - tac, rev command detailed explanation

<<:  Detailed explanation of MySQL sql99 syntax inner join and non-equivalent join

>>:  Detailed explanation of psql database backup and recovery in docker

Recommend

Detailed explanation of client configuration for vue3+electron12+dll development

Table of contents Modify the repository source st...

How to enable the root account in Ubuntu 20.04

After Ubuntu 20.04 is installed, there is no root...

Introduction to network drivers for Linux devices

Wired network: Ethernet Wireless network: 4G, wif...

How to Apply for Web Design Jobs

<br />Hello everyone! It’s my honor to chat ...

Win10 + Ubuntu20.04 LTS dual system boot interface beautification

Effect display The built-in boot interface is too...

Summary of commonly used performance test scripts for VPS servers

Here is a common one-click performance test scrip...

WeChat applet realizes the function of uploading pictures

This article example shares the specific code for...

JS ES6 asynchronous solution

Table of contents Initially using the callback fu...

Linux kernel device driver kernel linked list usage notes

/******************** * Application of linked lis...

Analysis of the reasons why MySQL field definitions should not use null

Why is NULL so often used? (1) Java's null Nu...

...

How to hide rar files in pictures

You can save this logo locally as a .rar file and...

Two ways to build Docker images

Table of contents Update the image from an existi...

Detailed installation process of MySQL 8.0 Windows zip package version

The installation process of MySQL 8.0 Windows zip...