Merge txt file: TXTcollector - merge

I am looking for an easy way (without windows commands) to merge several txt files.
Does anyone has an advice about the software TXTCollector? Is it a good one?
Thanks

A command prompt or .BAT/.CMD file can accomplish this easily by redirecting the output to a file.
type first.txt > merge.txt
type second.txt >> merge.txt
type third.txt >> merge.txt
A single redirection operator (e.g. >) will always create a new file with the output, overwriting any existing target file. Double redirection operators (e.g. >>) will append the output to an existing file or create a new file if one does not exist.
In the above .CMD script, the contents of first.txt, second.txt and third.txt will be in the new merge.txt.
EDIT Sample .CMD files
In its simplest form, a .CMD script that loops through the .txt files in a folder would look something like this.
#echo OFF
FOR %%c in (*.txt) DO TYPE %%c >> merge.txt
There is plenty of examples available on the web if you need to make adjustments for your particular situation.

Related

Powershell call a script from another scipt as if in a different folder

I use the video transcoding tools made by Don Melton over on GitHub to compress self filmed videos. Now I would like to automate this task by using a PowerShell script to loop over the contents of a folder as input arguments for the tool and have the output put into a seperate folder. My problem is that the tool is written in a way that it has no option to provide an output location, instead it always places the output files in the directory where it is called in. So when I cd into an "output" directory "next to" the one where my input files are, I then can call
other-transcode ../input/file.mp4
and the output file of the same name as the input file will be placed in the output directory.
Now when I want to use the command in a script, how do I tell PowerShell to run the command as if it was typed manually into a shell that was in the output directory at the moment?
For context, this is my end goal, but I think it is easier to split the complicated question into multiple ones.

Save as a .txt file CMD/powershell outputs

I write a command like tree and all outputs printed on the console.
I wanna save the printed outputs as a .txt file, the file path is gonna set the target terminal path.
How can I do that?
This line does what you are asking for. It should work both in CMD and PowerShell.
tree >> myfile.txt

Rename and overwrite files using wildcard in Windows

I am working on a script for auto deployment, where I need to replace my files with the same filenames.
For example, I have the following files in my current directory
deployment.properties
wrapper.conf
config.properties
Later, I will generate another set of files like this
deployment.properties.tokenized
wrapper.conf.tokenized
config.properties.tokenized
Lastly, I want to replace the existing config files (in the first code block) using the *.tokenized version and remove the tokenized files.
In Linux, the following can do the job. But I don't know how to do in Windows
for f in *tokenized;
do mv "$f" "`echo $f | sed s/tokenized//`";
done
I tried to use powershell's move-item, rename-item but still cannot figure out the right way to do it. Could somebody help? bat / powershell scripts are both welcomed. Using loop is also okay. Thank you.
It is almost the same code but in cmd / batch files we have access to the elements of the file name.
From command line
for %a in (*.tokenized) do move /y "%a" "%~na"
Or, for a batch file (you need to escape the for replaceable parameter)
for %%a in (*.tokenized) do move /y "%%a" "%%~na"
As the extension of the file (the text after the last dot) is .tokenized, when you request just the name (without extension) of the file being referenced (%%~na) you get the original file name.
This PowerShell script should do the job:
Get-ChildItem *.tokenized | % {
move $_.Name ([System.IO.Path]::GetFileNameWithoutExtension($_.Name)) -Force
}

How to copy files throuth a windows command line?

I want to copy many text files from one folder to another. The file names are contained in another text file. So the commands should be able to read in the file names and do the copy things. I can do this with R but it's very slow. I wonder if it's possible to do this with the command line? (I can copy single file with the command line, but don't know how to copy many with for or while loop or something.) Thanks in advance.
I found this question helpful: How do you loop through each line in a text file using a windows batch file?
This is what you need to just paste into the command line. If you want to save it in a bash file you need to use %% instead of % for variables.
for /F "tokens=*" %a in (myfile.txt) do copy "%a" "new folder\%a"
This simply loops through the file, and for each line does a copy of it to the new folder. The quotes are important in case of spaces in the filenames.

Passing Parameters/Argument to FTP filename from DOS

I am calling a FTP file from DOS, which holds ftp set of commands as follows:
ftp -s:ftpcmd1.txt
Now, the change requirement says, file is to be called multiple times with different file paths.
so, I need to write above statement, each time passing new file path as argument with FTP filename and writing something like "%1" in command inside ftp-file. Please help me with same. How do I do it.
Thanks.
I dont know if we can pass parameter to ftp script (atleast in DOS). But in the above case dynamically written out ftp script file would help. Small bat file which would do that is like below.
echo "user username pwd">ftpcmd1.txt
echo "bin">>ftpcmd1.txt
echo "put %1">>ftpcmd1.txt
echo "bye">>ftpcmd1.txt
ftp -n -i -v servername<ftpcmd1.txt
If you call this bat file with any file name as the first command line argument, it would transfer the file to target servername. Hope this is what you are looking for.