JOIN TWO OR MORE FILES TOGETHER – CAT PLUGIN
The Cat plugin can join two or more files together and has some additional features as well. The name cat is derived from the word concatenate. This plugin was written by Torbjorn Granlund and Richard M. Stallman from the GNU Project, based on the original implementation for UNIX. You can also handle special characters usually not supported by batch, with the help of this plugin. You can download this plugin from the official GitHub page.
cat <switch> file
-A, --show-all equivalent to -vET -b, --number-nonblank number nonblank output lines -e equivalent to -vE -E, --show-ends display $ at end of each line -n, --number number all output lines -s, --squeeze-blank never more than one single blank line -t equivalent to -vT -T, --show-tabs display TAB characters as ^I -u (ignored) -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB --help display this help and exit --version output version information and exit
USAGE & EXAMPLE
We can use this plugin to concatenate files together and exploit the additional feature of showing the special characters in a file that are usually not visible by default.
We will demonstrate how the plugin can be used, by concatenating the second file right after the first file without giving any space between them. First, we will call the plugin with just one file name, which returns its contents to STDOUT.
We can then join these two files and display the joined file, using the cat command as shown below.
cat file1 file2
CONCATENATING TWO FILES AND SAVING THEM IN A THIRD FILE
We can also save the concatenated result of two files in a third file, instead of displaying them in CMD. As shown in the example below, I have concatenated the files 1.txt and 2 .txt and saved the result in a third file (new.txt).
cat file1 file2 >> newfile
NOTE: You don’t have to create the third file. It will be created automatically, with the name you mention in CMD.
SHOW SPECIAL CHARACTERS
This plugin gives us the switch, -A, that will show all the special characters in a file that are usually hidden. As shown in the example below, it shows $ and ^M at the end of each line. Below, $ represents the end of a line, and ^M represents the use of the tab/line feed.
cat -A file
cat -E file
file -t file
As seen above, we can also use either -E or -t for displaying these special characters. Likewise, -E is used to show $ at the end of the line, while -t is used to show ^M where a new line is used.
NOTE: We can also use these switches while concatenating the files with the below syntax.
cat -A/-E/-t file
NUMBERING THE LINES
We can use this plugin to insert the line number in the relevant line of a file. To number the lines, we have two different types of switches.
In the example below, you can see it will number every line, whether it is blank or used.
cat -n file
cat -b file
This switch, unlike -n, will only number the lines with text, leaving the blank lines. Using this can be helpful when content is indented.
We can use –help to display the help menu, which contains the syntax of all switches available. We can display the version information of the plugin by using the –version as shown below.
This article shows how this plugin will help us concatenate/join two or more files together, and some features using the cat plugin. I hope you enjoyed reading this article, please share your thoughts below and make sure to join our Discord and YouTube community. For more plugins like this visit our site Batch-man. Thank you for reading.