The cat command in Linux is used to concatenate files and print to a standard output.
The type command is a Windows cat equivalent that works across a command-line prompt (CMD) and a Windows PowerShell.
In this short note i will show how to concatenate files and how to print the contents of a text file to the screen in Windows.
Cool Tip: Windows grep command equivalent in CMD and PowerShell! Read more →
`Cat` in CMD & PowerShell
Print the contents of a text file in CMD or Windows PowerShell (cat a file):
C:\> type file.txt
Create files:
C:\> echo "line from file1" > file1.txt C:\> echo "line from file2" > file2.txt
Concatenate files:
C:\> type file1.txt file2.txt > result.txt C:\> type result.txt line from file1 line from file2
Type: The type command in PowerShell is the alias of the Get-Content command.
I have found this “alternative” unsuitable for concatenating *binary* files, no matter what I do… When trying to concatenate binary archives to a decompression tool in x64 only capable recovery environment, sadly 32-bit builds of “cat” (GNU or BSD) for Win32 Portable Executables are not available.
This is a problem… It should not be insurmountable, but I don’t feel proficient enough to cleanly port GNU / BSD “cat”, and “type” seems not to be the answer. (unless you only care about text, in which case “fill your boots”)
The article is incorrect.
Type and get-Contents are specifically text based and will fail if they hit certain characters.
copy file con:
Thank you Carl, my thoughts exactly
You can use
c:\>copy /b file1.txt+file2.txt+fileN.txt result.txt
This works for ANY type of file (/b stands for ‘binary).
Regards
I get an error using ‘type’ to concatenate two files to stdout. Here’s the command:
type pc-holdingdir.txt pc-fromcddir.txt | sort /+40 >pc-mp3dir.txt
It seems to work, but issues the error message:
The process tried to write to a nonexistent pipe.
Error occurred while processing: pc-fromcddir.txt
Why does this occur, and how do I prevent it?