logo
  • Home
  • Test & Rank
  • About
  • Training
  • Programming
  • CS
  • IT
  • IS
  • ECE
  • EEE
  • EE
  • Civil
  • Mechanical
  • Chemical
  • Metallurgy
  • Instrumentation
  • Aeronautical
  • Aerospace
  • Biotechnology
  • Mining
  • Marine
  • Agriculture
  • MCA
  • BCA
  • Internship
  • Jobs
  • Contact

Questions & Answers

C Interview Questions
C++ Questions
Linux MCQs
C# Quiz
Java MCQs
JavaScript MCQs
SAN Questions
PHP Questions
Python Quiz

Computer Science Questions

Operating System Quiz
Computer Architecture MCQs
Software Architecture MCQs
Software Engineering MCQs
Artificial Intelligence MCQs
LISP Programming MCQs
Database Management MCQs
Computer Network MCQs
Microprocessor MCQs

C Programming Examples

Simple C Programs
C - Arrays
C - Matrix
C - Strings
C - Bitwise Operations
C - Linked Lists
C - Stacks & Queues
C - Searching & Sorting
C - Trees
C - Strings
C - File Handling
C - Mathematical Functions
C - Puzzles & Games
C Programs - Recursion
C Programs - No Recursion

Java Algorithms

Java - Numerical Problems
Java - Combinatorial Problems
Java - Graph Problems
Java - Hard Graph Problems
Java - Computation Geometry
Java - Sets & Strings
Java - Data-Structures
Java - Collection API Problems

C++ Algorithms

C++ - Numerical Problems
C++ - Combinatorial Problems
C++ - Graph Problems
C++ - Hard Graph Problems
C++ - Computation Geometry
C++ - Sets & Strings
C++ - Data-Structures
C++ - STL Library

C Algorithms

C - Numerical Problems
C - Combinatorial Problems
C - Graph Problems
C - Hard Graph Problems
C - Computation Geometry
C - Sets & Strings
C - Data-Structures

« Prev Page
Next Page »

“tac” Command Usage Examples in Linux

Posted on December 21, 2013 by Manish

This tutorial explains Linux “tac” command, options and its usage with examples.

tac – Concatenate and print files in reverse.

DESCRIPTION

advertisement

tac (which is “cat” backwards) concatenates each FILE to standard output just like the cat command, but in reverse: line-by-line, printing the last line first. This is useful (for instance) for examining a chronological log file in which the last line of the file contains the most recent information.

If no FILE is specified, or if the FILE is specified as “-“, tac reverses the contents of standard input.

SYNOPSIS

tac [OPTION]… [FILE]…

OPTIONS :

advertisement

-b, –before
attach the separator before instead of after
-r, –regex
interpret the separator as a regular expression
-s, –separator=STRING
use STRING as the separator instead of newline

EXAMPLES

1. Print the lines of file1.txt in reverse, from last line to first.

$ tac file1.txt

The word tac is reverse of the word cat. The tac command functionality is also reverse of the cat command. cat command prints the file. tac command prints the file in reverse order with the last line first as shown below.

$ cat file1.txt
01. Advanced C Programming Lab
02. Linux & C Debugging Techniques Lab
03. SAN Technology Training
04. SAN Administration Training
05. Linux Device Drivers
06. Linux Administration Training
07. Linux Systems Programming I
08. Linux Systems Programming II – IPCs
09. Linux Network Programming Lab
10. Linux Multi-threaded Programming Lab
11. Linux Kernel Internals Programming
12. Linux Kernel Debugging
13. Linux Virtualization Internals Programming
 
$ tac file1.txt
13. Linux Virtualization Internals Programming
12. Linux Kernel Debugging
11. Linux Kernel Internals Programming
10. Linux Multi-threaded Programming Lab
09. Linux Network Programming Lab
08. Linux Systems Programming II – IPCs
07. Linux Systems Programming I
06. Linux Administration Training
05. Linux Device Drivers
04. SAN Administration Training
03. SAN Technology Training
02. Linux & C Debugging Techniques Lab
01. Advanced C Programming Lab

2. Using the other options

advertisement
$ cat records 
---1---
1
2
3
---2
A
B
C
---3--
a
b
c
$ tac --before --regex --separator=^---[0-9]+-*$ records
---3--
a
b
c
---2
A
B
C
---1---
1
2
3

In this example the file records contains multiline records, each started with a line (^…$) that starts with —, followed by a number ([0-9]+) and an optional sequence of minus signs (-*). One can see the order of lines in each record and its header line are preserved.

Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.

If you wish to look at all Linux commands and their usage examples, go to Linux Commands Tutorial.
« Prev Page - 10+ “od” Command Usage Examples in Linux
» Next Page - 5+ “dig” Command Usage Examples in Linux

« 5 “shred” Command Usage Examples in Linux
5+ “dig” Command Usage Examples in Linux »
advertisement

Deep Dive @ Sanfoundry:

  1. C# Programming Examples on Files
  2. C# Programming Examples on LINQ
  3. C# Programming Examples
  4. C Programming Examples
  5. C Programming Examples on File Handling
  6. About
  7. Bangalore Training – SAN, C, Linux Kernel and Device Drivers Training
  8. Online Training – SAN, C, Linux Kernel & Device Drivers Training
  9. Linux Questions and Answers
  10. Linux Command Tutorials with Examples and Explanations
Manish Bhojasia
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Facebook | Twitter

Best Careers

Developer Tracks
SAN Developer
Linux Kernel Developer
Linux Driver Developer
Linux Network Developer

Live Training Photos
Mentoring
Software Productivity
GDB Assignment
Sanfoundry is No. 1 choice for Deep Hands-ON Trainings in SAN, Linux & C, Kernel Programming. Our Founder has trained employees of almost all Top Companies in India such as VMware, Citrix, Oracle, Motorola, Ericsson, Aricent, HP, Intuit, Microsoft, Cisco, SAP Labs, Siemens, Symantec, Redhat, Chelsio, Cavium, ST-Micro, Samsung, LG-Soft, Wipro, TCS, HCL, IBM, Accenture, HSBC, Mphasis, Tata-Elxsi, Tata VSNL, Mindtree, Cognizant and Startups.

Best Trainings

SAN I - Technology
SAN II - Admin
Linux Fundamentals
Advanced C Training
Linux-C Debugging
System Programming
Network Programming
Linux Threads
Kernel Programming
Kernel Debugging
Linux Device Drivers

Best Reference Books

Computer Science Books
Algorithm & Programming Books
Electronics Engineering Books
Electrical Engineering Books
Chemical Engineering Books
Civil Engineering Books
Mechanical Engineering Books
Industrial Engineering Books
Instrumentation Engg Books
Metallurgical Engineering Books
All Stream Best Books

Questions and Answers

1000 C Questions & Answers
1000 C++ Questions & Answers
1000 C# Questions & Answers
1000 Java Questions & Answers
1000 Linux Questions & Answers
1000 Python Questions
1000 PHP Questions & Answers
1000 Hadoop Questions
Cloud Computing Questions
Computer Science Questions
All Stream Questions & Answers

India Internships

Computer Science Internships
Instrumentation Internships
Electronics Internships
Electrical Internships
Mechanical Internships
Industrial Internships
Systems Internships
Chemical Internships
Civil Internships
IT Internships
All Stream Internships

About Sanfoundry

About Us
Copyright
Terms
Privacy Policy
Jobs
Bangalore Training
Online Training
Developers Track
Mentoring Sessions
Contact Us
Sitemap
© 2011 Sanfoundry. All Rights Reserved.