The following blog will cover the alternatives of the cmdlet “Cat”.
How to Quickly Display Files With PowerShell Cat?
The files in PowerShell can be displayed with the aid of the “Cat” cmdlet alternative which is “Get-Content”. Multiple examples of the “Get-Content” cmdlet are illustrated below.
Example 1: Use the “Get-Content” Cmdlet to Read a File
The following example will retrieve or read the content of the specified file:
According to the above code, first add the “Get-Content” cmdlet and specify the address of the file to be read:
Example 2: Use the “Get-Content” Cmdlet to Merge or Concatenate Two Files
The example below will help join or merge two files together with the aid of “Get-Content” cmdlet:
In this stated code below:
- First, add the “Get-Content” cmdlet followed by the two file paths separated by commas.
- After that, specify the pipeline “|”, define the “Out-File” cmdlet, and assign the target file path:
Let’s verify whether the files were merged or not by using the command below:
Example 3: Use the “Get-Content” Cmdlet to Display the First Four Lines of Text
The following command will get the initial four lines of the text file:
In the code above, add the “-TotalCount” parameter and assign the value “4” to it:
Example 4: Use the “Get-Content” Cmdlet to Display the Last Four Lines of Text
This example will retrieve the four bottom lines of the text file:
In the above code, simply add the “-Tail” parameter and assign the value “4” to it:
That was all about displaying files using PowerShell.
Conclusion
The “Cat” cmdlet is a Linux base cmdlet not supported in PowerShell. However, PowerShell has its alternative “Get-Content” cmdlet. It performs all the operations that the “Cat” cmdlet can. These operations include merging, concatenating, reading, or displaying text files. This blog has elaborated on displaying the files with PowerShell.