1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: [batch + awk]

Discussion in 'DOS/Other' started by konto204, Apr 21, 2010.

Thread Status:
Not open for further replies.
  1. konto204

    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 ;)
     
  2. TheOutcaste

    TheOutcaste

    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^|
    )
    
     
  3. konto204

    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...
     
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 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/918336

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice