# Solved: [batch + awk]



## konto204 (Apr 21, 2010)

Hello 

Please help me with this problem:
I need a script that:
1. For all files with extensions *.log from catalog (e.g. D:\temp) copy file names without extensions to file ccc.txt

2. Then script create file that look something like this:

33|EE|first_file_name_from_ccc.txt |77|CC|
33|EE|second_file_name_from_ccc.txt |77|CC|
...
33|EE|last_file_name_from_ccc.txt |77|CC|

part "33|EE" and "|77|CC|" always looks the same, 
part with file name always must have 25 characters - I mean: "file name from ccc.txt" + spaces = 25

And I must have this script in BATCH or AWK for Windows.
Somebody help me?
Sorry for my english, it isn't my best side


----------



## TheOutcaste (Aug 8, 2007)

I think this will do what you want. Set the two paths as needed in the first two set statements:


```
@Echo Off
SetLocal EnableDelayedExpansion
Set _Source=D:\Temp
Set _OutputDir=C:\Scripts
Set _CCC=%_OutputDir%\ccc.txt
Set _Ofile=%_OutputDir%\Output.txt
If Exist "%_CCC%" Del "%_CCC%"
If Exist "%_Ofile%" Del "%_Ofile%"
For /F "Tokens=* Delims=" %%I In ('Dir /A-D /B "%_Source%\*.log"') Do >>"%_CCC%" Echo.%%~nI
For /F "Tokens=* Delims=" %%I In ('Type "%_CCC%"') Do (
   Set _Temp=%%I                         E
   Set _Temp=!_Temp:~0,25!
   >>"%_Ofile%" Echo.33^|EE^|!_Temp!^|77^|CC^|
)
```


----------



## konto204 (Apr 21, 2010)

Thank you very much !!! Now - I know much more about EnableDelayedExpansion and I know why my batch dosn't work...


----------

