Creating a global master file.

Hi everybody,

I hope you are well and can help.

I have a top folder. Let's call is "Master".
Underneath this folder, I have many subfolders, of unknown number, but all will contain 3 files, with similar naming convention.
So, the folder structure could look like this..

 Parent      Child
 Folder      Folder   3 files of similar naming convention

 Master
    |_______ ad
                      |_________1of3_workings_ad.txt
                      |_________2of3_sorted_ad.txt
                      |_________3of3_master_ad.txt
    |_______ batchfile
                      |_________1of3_workings_batchfile.txt
                      |_________2of3_sorted_batchfile.txt
                      |_________3of3_master_batchfile.txt
    |_______ sccm
                      |_________1of3_workings_sccm.txt
                      |_________2of3_sorted_sccm.txt
                      |_________3of3_master_sccm.txt
    |_______ vmware
                      |_________1of3_workings_vmware.txt
                      |_________2of3_sorted_vmware.txt
                      |_________3of3_master_vmware.txt


 As you can see, the naming conventions for the 3 files are:

 1of3_workings_*.txt
 2of3_sorted_*.txt
 3of3_master_*.txt

 where "*" is the same name as the folder name given for the child folder these files reside in.

 ===========================================================================

What I want to do is the following:

I want to create a script, that will create a text file that contains the contents of every 3of3_master_*.txt in the above folder structure.

So, for example, in the above scenario, this is how it would look....

script.cmd
1.Create a text file called 'GLOBAL-MASTER.txt'.
2.Read every subfolder of the top folder 'Master', looking for a file called '3of3_master_*.txt'
3.For each file 3of3_master_*.txt found, read its contents and copy into the 'GLOBAL-MASTER.txt' file created in step 1.
4.Leave a line or 2 blank space between each '3of3_master_*.txt' in the new GLOBAL-MASTER.txt file.

Here for example, are the contents of each file targetted...


------------------------------------------------- 3of3_master_ad.txt

-------------------------------------------
Master: ad
-------------------------------------------
 
item1,item2,item3;  


------------------------------------------------- 3of3_master_batchfile.txt

-------------------------------------------
Master: batchfile
-------------------------------------------
 
batch,token;  



------------------------------------------------- 3of3_master_sccm.txt

-------------------------------------------
Master: sccm
-------------------------------------------
 
deployment type;  


------------------------------------------------- 3of3_master_vmware.txt

-------------------------------------------
Master: vmware
-------------------------------------------
 
esx,vsphere;  



The output by running the script will be like below.



=====================================================================  GLOBAL-MASTER.txt

 
-------------------------------------------
Master: ad
-------------------------------------------
 
item1,item2,item3;  


 
-------------------------------------------
Master: batchfile
-------------------------------------------
 
batch,token;  


-------------------------------------------
Master: sccm
-------------------------------------------
 
deployment type;  


-------------------------------------------
Master: batchfile
-------------------------------------------
 
esx,vsphere;  




So, you can see, that the script will create a text file called 'GLOBAL-MASTER.txt, which will contain the contents of all 3of3_master_*.txt in the above folder structure.

Any help greatly appreciated.
LVL 1
Simon336697Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jmcgOwnerCommented:
The shell "glob" operator will do the subdirectory search for you easily enough:

cat Master/*/3of3_master*.txt >GLOBAL-MASTER.txt

Open in new window


But you want to decorate the GLOBAL-MASTER.txt with extra spaces, so something more like

for file (Master/*/3of3)master*.txt )
do
cat $file
echo ""
echo ""
done >GLOBAL-MASTER.txt

Open in new window


This isn't exactly the contents of your example, but maybe it's close enough?
0
Simon336697Author Commented:
Hi jcmg,
Thanks so much for that.
That looks unix like.

Im more of a wintel person.
0
NVITCommented:
rem @echo off
rem - Copies contents of found files into master FNGlobal file
rem - FNGlobal is placed in the %temp% folder.
rem - Adjust TopDirName and TopDir values as needed.

set FNAll=%temp%\%~n0_All.txt
set FNGlobal=%temp%\%~n0_GLOBAL-MASTER.txt
set TopDirName=master
set TopDir=c:\%TopDirName%

if exist "%FNGlobal%" del "%FNGlobal%"
type nul>"%FNGlobal%"

pushd "%TopDir%"
dir /b /s "3of3_%TopDirName%*.txt" > "%FNAll%"
for /f %%a in (%FNAll%) do (
  copy /a "%FNGlobal%"+"%%a" "%FNGlobal%">nul
  >> "%FNGlobal%" echo.
  >> "%FNGlobal%" echo.
)
popd

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Simon336697Author Commented:
thx so much and sorry for the delay. happy christmas to all.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.