Windows OS

Is There any Replacement for cat Command in Windows

The word “cat” is derived from “Concatenate”. cat is a Linux and Unix-based command line primarily used for concatenation and to read, merge, and display file content sequentially. In Windows, there are some commands that perform the same functionality that the cat command do.

This article will discuss replacements for the cat command in Windows:

Let’s get started!

What is the Replacement for cat Command in Windows Command Prompt?

The replacement for the cat Command in Windows Command Prompt is the “type” and “copy” command.

Follow the below-given methods to use these commands.

Method 1: Use “type” as cat Command Replacement in Windows

To use the “type” command on the Windows Command prompt, check out the below-provided steps.

Step 1: Open Command Prompt

First, press “Window+R” to open the “Run” box, and search for “CMD” to open Command Prompt:

Step 2: Create New File

Create a new text file named “File.txt” using “echo.” command and place some text in it as we have added “Hello LinuxHint”:

>echo. Hello LinuxHint > File.txt

Step 3: Use “type” Command to Read and Display File Content

Then, utilize the “type” command as a replacement for the “cat” command to read and display file content on Command Prompt:

>type File.txt

Use “type” Command to Concatenate Files

Let’s use the “type” command to concatenate the content of two different files into a new file. To do so, follow the listed step.

Step 1: Create Files

First, create two new files named “File1.txt” and “File2.txt” using the provided “echo” commands:

>echo Hello World! >File1.txt

>echo Welcome to LinuxHint > File2.txt

Step 2: Concatenate Files

Use the “type” command to concatenate two files in the “New.txt” file:

>type File1.txt File2.txt > New.txt

Step 3: View Concatenated File

To view the concatenated content, the “type” command and specify the name of the newly created file:

>type New.txt

The below-given output indicates that we have successfully concatenated content in the “New.txt” file:

Let’s head towards the next method.

Method 2: Use “copy” as cat Command Replacement in Windows

The “copy” command can also be used as a “cat” command for content concatenation. But, it cannot be utilized to read or display file content.

Step 1: Concatenate Files

Concatenate the existing two files into a “Sample.txt” file using the provided command:

>copy /b File1.txt+File2.txt Sample.txt

The “copy” command will copy the content of “File1.txt” and “File2.txt” and paste them into a new “Sample.txt” file:

Step 2: Read and Display Concatenated File

Let’s confirm the concatenated content using the “type” command:

>type Sample.txt

Take a look at the replacement for the cat command in Windows PowerShell.

What is the Replacement for cat Command in Windows PowerShell?

The aliases or replacements for cat Command in Windows PowerShell are listed below:

We will now discuss each of them one by one!

Method 1: Use “Get-content” as cat Command Replacement in Windows

The “Get-content” is a Windows PowerShell-supported command and a replacement for the “cat”.It is utilized to retrieve the content of the chosen file.

To practice the usage of the “Get-content” command, first, open the Windows PowerShell by searching it in the “Startup” menu:

Use “Get-content” to Read and Display File Content

Now, specify the file name read and print out its content with the help of the “Get-content” command:

> Get-content File1.txt

Use “Get-content” Command to Concatenate Files

To utilize the Get-content command to concatenate different files, follow the given steps.

Step 1: Concatenate Files

Use the mentioned command to concatenate different files into a new file:

> Get-content File1.txt,File2.txt | out-file NewFile.txt

Here, the “Get-content” command is used to get the content of files. The pipe “|” operated will send content to the “out-file” command to concatenate the content of these files into the “NewFile.txt” command:

Step 2: View File Content

Verify the concatenation of files through the below-given command:

> Get-content NewFile.txt

Method 2: Use “type” Command as cat Command Replacement in Windows

The “type” command is also a replacement for a “cat” command in Windows. Let’s practice the “type” command usage on Windows PowerShell.

Use “type” Command to Read and Display File Content

Use the “type” command on Windows PowerShell to read and display file content:

> type File1.txt

Use “type” Command to Concatenate Files

Concatenate different files into a new file using the “type” command; as we have concatenated “File1.txt” and “File2.txt” into a new file “File3.txt”:

> type File1.txt, File2.txt > File3.txt

> type File3.txt

Method 3: Use “gc” as cat Command Replacement in Windows

The Windows PowerShell “gc” command is another alias for the “cat” command. Let’s use it on PowerShell.

Use “gc” Command to Read and Display File Content

Utilize the “gc” command to read and view the content of the provided file:

> gc File1.txt

Use “gc” Command to Concatenate Files

The “gc” command can be used to concatenate specified files as the “cat” command. For this purpose, run the provided command and redirect the content of the “File1.txt” and “File2.txt” to the “NewFile1.txt” with the help of the “>” operator:

> gc File1.txt,File2.txt >NewFile1.txt

> gc NewFile.txt

We have described the various Windows commands that are considered replacements for the cat command in Window

Conclusion

Various Windows commands act as the replacement for the cat command such as the “type” and “copy” commands, which can be used in Command Prompt. PowerShell also supports some commands such as “Get-content“, “type”, and “gc” that can be utilized for the same purpose. We have elaborated on how to use different Windows commands to concatenate, read and view files as a replacement for the cat command.

About the author

Rafia Zafar

I am graduated in computer science. I am a junior technical author here and passionate about Programming and learning new technologies. I have worked in JAVA, HTML 5, CSS3, Bootstrap, and PHP.