Solved: [batch + awk]

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

konto204

Thread Starter
Joined
Apr 21, 2010
Messages
2
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 ;)
 
Joined
Aug 7, 2007
Messages
9,028
I think this will do what you want. Set the two paths as needed in the first two set statements:

Code:
@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

Thread Starter
Joined
Apr 21, 2010
Messages
2
Thank you very much !!! Now - I know much more about EnableDelayedExpansion and I know why my batch dosn't work...
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Members online

Top