cat command for windows - windows

I have 4 files
sitefiles.tar.gz.splitaa
sitefiles.tar.gz.splitab
sitefiles.tar.gz.splitac
sitefiles.tar.gz.splitad
I need a command or program that works like "cat" on linux. that way I can join all the 4 files into 1 file

Windows Powershell supports cat.
However you can do it even simpler, using a normal console:
copy /b sitefiles.tar.gz.split* sitefiles.tar.gz
This will append all files into sitefiles.tar.gz.
If you want to join specific files, or if you want to append them in a specific order (default is sorting the filenames alphabetical) append them using +:
copy /b sitefiles.tar.gz.splitaa+sitefiles.tar.gz.splitab+sitefiles.tar.gz.splitac+sitefiles.tar.gz.splitad sitefiles.tar.gz

Related

Windows 10 Command Prompt rename files overwrites file names instead of prepending

I have these files in a folder:
aaa.txt
bbb.txt
ccc.txt
I want to prepend all the filenames with 1_, so I try to write this in a Windows command prompt:
rename * 1_*
Doing so I want to get this result:
1_aaa.txt
1_bbb.txt
1_ccc.txt
But instead i get this:
1_a.txt
1_b.txt
1_c.txt
Instead of prepending it is just overwriting the names from the start. According to this (https://www.computerhope.com/renamehl.htm) article that is indeed the intended behavior.
But in this (https://www.windowscentral.com/how-rename-multiple-files-bulk-windows-10) article they show an example where they are increasing the length of the first part of the filename like this:
ren nyc_*.* newYork_*.*
So that seems to be similar to what I want to do, but when I try that exact example it does not work like that. Again, it just overwrites the first part the name without adding anything, and then I end up with nyc_(1).jpg becoming newYork_.jpg (the unique number is overwritten).
Is the second article plain wrong? How do I simply prepend something to a bunch of files with a batch line?
One method is to knock up a temporary batch file to do your renaming.
First, dump your directory to a text file with formatting turned off:
dir *.txt /B > list.bat
Open it in Notepad and then copy that bare listing into the likes of Excel (or if you have a text editor with powerful features you can use it.) You can then create a formula, like:
="rename " & A1 & " 1_" & A1
Which will build you a list of individual rename commands changing each file one at a time, like this:
A B
aaa.txt rename aaa.txt 1_aaa.txt
bbb.txt rename bbb.txt 1_bbb.txt
ccc.txt rename ccc.txt 1_ccc.txt
Copy that new column back into notepad and save it.
Run and discard your new batchfile and everything will be renamed over.
For your nyc to NewYork, you need a bit more work...
="rename " & A1 & " NewYork" & MID(A1,4,99)
...will strip the left three characters from the name replace them to give you:
rename nyc_(1).jpg NewYork_(1).jpg
forfiles /m *.txt /C "cmd /c rename #file 1_#file"

Command prompt batch renaming results in syntax error

I need to rename 80k files in multiple folders & subfolders in the same directory. I have been trying to use ren but have been unsuccessful; I get an incorrect syntax error.
My old name looks like this:
c:/users/alice/BiDIR_DOCS_2017_Nov08020423\Company,LLC##NA##7967425.00##7967425.00\Company LLC A and A - Aug2017.pdf BiDIR_DOCS_2017_Nov08020423\Company, LLC##NA##7967425.00##7967425.00\document_# (x.y.z)-test~.pdf
and my new name looks like this:
c:/users/alice/BiDIR_DOCS_2017_Nov08020423\Company,LLC##NA##7967425.00##7967425.00\Company LLC A and A - Aug2017.pdf BiDIR_DOCS_2017_Nov08020423\Company, LLC##NA##7967425.00##7967425.00\system, a old name~ ` to # system b document (xyz)-test.pdf
I have the existing directory print in one column of Excel and in the next column what I want the directory print to be.
I'm not sure if I'm starting my ren command at the right hierarchy of my directory, or if I need quotation marks to keep the spaces and symbols in my new name.
I have tried improvising and testing on my own without success and I cannot find an article online on point.
Try FAR (find and replace) - it a free utility that works well.
http://findandreplace.sourceforge.net/

Windows batch - concatenate multiple text files into one

I need to create a script, which concatenates multiple text files into one.
I know it's simple to use
type *.txt > merged.txt
But the requirement is to "concatenate files from same day into file day_YYYY-DD-MM.txt" I am a Linux user and Windows batch is hell for me. It's Windows XP.
Windows type command works similarly to UNIX cat.
Example 1: Merge with file names (This will merge file1.csv & file2.csv to create concat.csv)
type file1.csv file2.csv > concat.csv
Example 2: Merge files with pattern (This will merge all files with csv extension and create concat.csv)
When using asterisk(*) to concatenate all files. Please DON'T use same extension for target file(Eg. .csv). There should be some difference in pattern else target file will also be considered in concatenation
type *.csv > concat_csv.txt
At its most basic, concatenating files from a batch file is done with 'copy'.
copy file1.txt + file2.txt + file3.txt concattedfile.txt
In Win 7, navigate to the directory where your text files are. On the command prompt use:
copy *.txt combined.txt
Where combined.txt is the name of the newly created text file.
Place all files need to copied in a separate folder, for ease place them in c drive.
Open Command Prompt - windows>type cmd>select command prompt.
You can see the default directory pointing - Ex : C:[Folder_Name]>.
Change the directory to point to the folder which you have placed files to be copied, using ' cd [Folder_Name] ' command.
After pointing to directory - type 'dir' which shows all the files present in folder, just to make sure everything at place.
Now type : 'copy *.txt [newfile_name].txt' and press enter.
Done!
All the text in individual files will be copied to [newfile_name].txt
I am reiterating some of the other points already made, but including a 3rd example that helps when you have files across folders that you want to concatenate.
Example 1 (files in the same folder):
copy file1.txt+file2.txt+file3.txt file123.txt
Example 2 (files in same folder):
type *.txt > combined.txt
Example 3 (files exist across multiple folders, assumes newfileoutput.txt doesn't exist):
for /D %f in (folderName) DO type %f/filename.txt >> .\newfileoutput.txt
We can use normal CAT command to merge files..
D:> cat *.csv > outputs.csv
cat "input files" > "output files"
This works in PowerShell, which is the Windows preferred shell in current Windows versions, therefore it works. It is also the only version of the answers above to work with large files, where 'type' or 'copy' fails.
Try this:
#echo off
set yyyy=%date:~6,4%
set mm=%date:~3,2%
set dd=%date:~0,2%
set /p temp= "Enter the name of text file: "
FOR /F "tokens=* delims=" %%x in (texto1.txt, texto2.txt, texto3.txt) DO echo %%x >> day_%temp%.txt
This code ask you to set the name of the file after "day_" where you can input the date.
If you want to name your file like the actual date you can do this:
FOR /F "tokens=* delims=" %%x in (texto1.txt, texto2.txt, texto3.txt) DO echo %%x >> day_%yyyy%-%mm%-%dd%.txt
You can do it using type:
type"C:\<Directory containing files>\*.txt"> merged.txt
all the files in the directory will be appendeded to the file merged.txt.
copy is definitely much faster than type - but it sometimes (with large files?) adds a SUB character at the end of the file. So, strictly speaking, it does not simply concatenate the files in the same way as cat in Unix.
So, the correct answer is to use cat - either in something like Git Bash (where it has the same syntax as in Unix), or PowerShell (where it does not).

Windows Batch file Dynamic create statements

I need to get a list of file names from a directory using a windows batch program. I would like to take each FILE NAME and combine that with another command line statement.
Note i only need the file name not the contents of the file.
How would this be done?
If i have a 'Data' directory on the D drive with the below files (note there could be many files)
--------------
myFile1.abc
myfile2.abc
------------------
How could i dynamically create something like this using a windows batch program?
move C:\myFile1.abc C:\newdir
move C:\myFile2.abc C:\newdir
note - (i know there is a easier way move files but but i am trying to understand the logic so i can use it in a different command)
You can use a for loop:
for %%X in (D:\*) do (
echo move %%X C:\newdir
)
Try on the command line:
for %X in (D:\DataFiles\*) do echo move "%~fX" C:\newdir>>logfile.txt
It puts all file names from D:\DataFiles in logfile.txt (except hidden files).

How do I append to a file using the COPY command

I'm running Windows 7 Ultimate x64, but my experience dates back to DOS 3.0.
Since like DOS 3.1 you've been able to append a file to another one with this use of the COPY command:
COPY FILE1+FILE2=FILE1
Making the need for a temporary FILE3 unnecessary.
It was a very convenient command since whenever you added a new program you often needed to update your CONFIG.SYS and AUTOEXEC.BAT files.
It also used to be that getting the order correct was importiant, otherwise you'd end up with an empty FILE1.
But today when I tried that, it left FILE1 untouched, and when I reversed the order, it (understandably) made FILE1 a copy of FILE2.
Does anyone know if it's been replaced with another method, and when this change happened?
EDIT:
I've been doing more testing, and oddly even though the above code won't work, you still can sill copy from the console and append that to an existing file like this:
copy file1+con=file1
Type some text to append to file1
^Z ([CTRL]+Z the End Of File character)
I'm wondering if my version of Windows is messed up somehow. Can any body replicate my findings?
EDIT:
It works on 95 / 98 / ME / 2000 / XP / XP Mode / 7 Professional x64 / 8 x64. So I imagine that it's not a 7 Ultimate x64 problem, but rather an issue with my machine.
* Sigh *
EDIT:
Last edit, I promise. :)
It was not an issue with my machine, it was an issue with File1. Apparently when I first appended File2 to it, the [CTRL]+Z (EOF character) never got overwritten, causing the file to look like this:
Original Data
Original Data
[EOF]
Appended Data
Appended Data
Appended Data
You can duplicate this yourself with the following experiment from at the command prompt. (Where ^Z is the character [CTRL]+Z )
At the command prompt type:
copy con file1
File One
^Z^Z
copy con file2
File Two
^Z
copy con file3
File Three
^Z
copy file1+file2=file1
copy file2+file3=file2
TYPE file1
TYPE file2
You will see:
file1
File One
file2
File Two
File Three
You can type file2 >> file1 or use nearly any other method of concatenating files, and when you type file1 it will still only appear to contain File One. BUT if you use FIND "searchterm" file to parse the file it will show you what's REALLY going on. In this case type:
FIND " " file1
And you will be rewarded with:
---------- FILE1
File One
→File Two
Windows 8 x86:
Microsoft Windows [Version 6.2.9200]
(c) 2012 Microsoft Corporation. All rights reserved.
C:\Users\Nikos>echo foo>file1
C:\Users\Nikos>echo bar>file2
C:\Users\Nikos>copy /b file1 + file2 file1
file1
file2
1 file(s) copied.
C:\Users\Nikos>type file1
foo
bar
What about type file2 >> file1
Answer to: "How do I append to a file using the COPY command"
WARNING: If you have a list of files you wish to combine via COPY command, it's simple but can potentially destroy your files.
Dangerous Way:
copy /b one + two + three -- will append contents of "two" and "three" to the file "one" . So the original "one" now has contents of 3 files in proper sequence. If during copy-process things go wrong, you'll have no way of recovering original "one", as it will be corrupt and your data would essentially be lost. There's almost Never a reason to use this way.
Safe Way:
copy /b one + two new_filename -- will combine 2 files (you can list more than two of course), creating a new_filename containing "one" and "two" in proper sequence, and leaving original files intact.
make sure you start with fresh files you never tried to copy over.
I just found that on my (XP sp3) copy a+b a without /b appends 1A (SUB) to the end of the file which makes anything after it disappear from output of type (but more will show it). Copy /b a+b a works.
#echo off
cls
type "file2.txt" >> "file1.txt"
exit
Did you try copy /b file1 + file2 file1
copy /b input1 + input2 output
del input1
ren output input1
Maybe this? :P
C:\Users\Nikos>type file1
foo
bar
C:\Users\Nikos>copy file1+con=file1
file1
con
ihdui
ohisd
^Z
1 file(s) copied.
C:\Users\Nikos>type file1
foo
bar
ihdui
ohisd
Wait! There is more! (Win7 Pro)
>ver
Microsoft Windows [Version 6.1.7601]
>copy file.a.txt + file.b.txt file.ab.txt
file.a.txt
1 file(s) copied
>copy fileA.txt + fileB.txt fileAB.txt
fileA.txt
fileB.txt
1 files(s) copied
Putting aside the "1 file(s) copied" notification, it just doesn't like files with funny names.
To copy to a binary file ...
Put all files in same folder e.g. G:\Files
g:
cd Files
copy /B *.* TargetFilename.ext
and .ext is the type of file required
echo . 2>new.mp3
rem create a new empty.
for /f "delims=" %%i in ('dir /b *.mp3') do copy /b "%cd%\new.mp3"+"%cd%\%%i.mp3" %cd%\new.mp3
rem loop merge mp3 to new.mp3
rem or you can edit a list to merge files
for /f "delims=" %%i in (list.txt) do copy /b "%cd%\new.mp3"+"%cd%\%%i.mp3" %cd%\new.mp3
Put all the files in the same folder.
copy *.* ´target.ext'
????
Profit!

Resources