I have 10 files like below:
file1.txt(file content = "i contain text for file1")file2.txt(file content = "i contain text for file2")file3.txt(file content = "i contain text for file3")
and so
I am trying to do a TYPE command like:
type file*.txt > OUTPUT.txt this works to output the file contents only. i need output to also have filename for each file.
my output.txt file should look like this:
file1.txt = "i contain text for file1" file2.txt = "i contain text for file2" file3.txt = "i contain text for file3" 23 Answers
Create a batch file called proc.bat which contains:
echo %1=>>output.txt type %1>>output.txt Then use this command:
for %v in (file*.txt) do proc %v Use next command from cmd window:
>output.txt (for /F "tokens=1* delims=:" %G in ('findstr "^" "file*.txt"') do @echo %G = "%H") If used in a batch script, double percent signs in for loop inner variables (i.e. %%G, %%H instead of %G, %H respectively):
@echo off >output.txt (for /F "tokens=1* delims=:" %%G in ('findstr "^" "file*.txt"') do echo %%G = "%%H") Resources (required reading):
- (command reference) An A-Z Index of the Windows CMD command line
- (additional particularities) Windows CMD Shell Command Line Syntax
- (
%Getc. special page) Command Line arguments (Parameters) - (
>special page) Redirection
You can try:
for /l %f in (1,1,3) do echo|set /p="File %f = " >> output.txt & type file%f.txt >> output.txt This will yield a file that looks like:
File 1 = Text in file1 File 2 = Text in file2 File 3 = Text in file3 The for /l command counts from 1 to 3 in increments. In general (start,increment,end).