Halia
asked on
Batch File to return text file name & data
Hello,
I need a Batch file that will produce a text that will have the name of the file and the data (all the files have 1 line only)
Example - ProdCount.txt has 1 record in it that tells me a count of the Prod.txt file (54000 records in file)
So my output would be...
ProdCount.txt 54000 Records in File
EmpInfo.txt 170000 in file
etc.
Any suggestions?
Thanks in advance,
Trish
Hope I have this in the right zone!
I need a Batch file that will produce a text that will have the name of the file and the data (all the files have 1 line only)
Example - ProdCount.txt has 1 record in it that tells me a count of the Prod.txt file (54000 records in file)
So my output would be...
ProdCount.txt 54000 Records in File
EmpInfo.txt 170000 in file
etc.
Any suggestions?
Thanks in advance,
Trish
Hope I have this in the right zone!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Actually the FINDSTR approach is easier, but you need to specify a wildcard in order to get the filename as part of the output:
FINDSTR . C:\path\*.txt > myout.txt
FINDSTR . C:\path\*.txt > myout.txt
revising my first script to include "Records in file"
@echo %%F %%C Records in file
@echo %%F %%C Records in file
ASKER
Ok....this is working -
@echo off
for %%F in (*.count) do for /f "delims=" %%C in ('type %%F') do @echo %%F %%C
Count.bat > Counts.txt
I get my file (PERFECT) but the Window is staying open. I see the last record and it stops and sits there.
What do I need to change?
@echo off
for %%F in (*.count) do for /f "delims=" %%C in ('type %%F') do @echo %%F %%C
Count.bat > Counts.txt
I get my file (PERFECT) but the Window is staying open. I see the last record and it stops and sits there.
What do I need to change?
add the following line to the bottom of the script:
exit
exit
ASKER
Thank you so much!!!!! You have just saved hours of cutting and pasting!
If the file only has one line, and you just want to return it's contents...
FINDSTR . C:\path\filename.txt