Ubuntu Linux: Concatenate Text Files Command

How do I concatenates the text files called first.doc and second.doc and writes the result to final.doc under Ubuntu Linux operating systems?

You need to use the cat command to show a text file or concatenates the text files under Ubuntu or Unix like operating systems. The syntax is as follows to see the contents of the file foo.txt in the current directory to screen:
Tutorial details
DifficultyEasy (rss)
Root privilegesNo
RequirementsNone
TimeN/A

ADVERTISEMENTS

cat foo.txt

To concatenates the text files the syntax is:

cat file1 file2 > file3

The output redirector (>) symbol used to redirect output of two files to the file3.

Example

Create a file called first.doc, enter:

echo 'This is a test and stored in first.doc file.' > first.doc
cat first.doc

Create a file called second.doc, enter:

echo 'This is a test and stored in second.doc file.' > second.doc
cat second.doc

Verify both file exists in the current directory with the ls command:

ls *.doc

To concatenates both files and store the result to final.doc, enter:

cat first.doc second.doc > final.doc
ls -l *.doc
cat final.doc

Sample outputs:

Fig.01: cat command in action

Fig.01: cat command in action

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
2 comments… add one
  • Liam Jul 30, 2013 @ 19:09

    Well, *this* is completely useless when dealing with actual .doc files in the wild (which are pretty much always Microsoft Word files).

    • pantuts Oct 27, 2013 @ 18:06

      well that’s only a demo, and its linux if you know what i mean.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.