Solved Run .AWK file to format data in all files in a location.

June 19, 2012 at 12:11:48
Specs: Windows 7

First of all, I am a newbie to batch programming so please be easy on me. I have to apply a format.awk file on all the .DAT files located in a folder and generate the formatted files in a different location, but with word "awked" in the file name. Please help me.....

Source Location has files:


I have to apply the awked file (Format.AWK) on each of the file above and generate formatted files as:


Thank you!!

See More: Run .AWK file to format data in all files in a location.

Report •

June 19, 2012 at 17:43:38
for /f "tokens=1* delims=(" %%a in ("%fname%") do set newfname=%%aAwked(%%b

Report •

June 19, 2012 at 18:21:06
I have an awk file named Format.AWK and it is supposed to format each of the files, ex: File(1).DAT and generate formatted file as FileAwked(1).DAT

The usage of the Format.AWK to apply on the DAT file would be like below, but that is for one file and I have to do the same for a bunch of files in a directory location.

GAWK -f %FormatFile%.AWK %FileLocation%\FileName.dat > %FileLocation%\FileNameAwked.dat

I think I would have to do a for loop for the files in the location, but not sure how to rename the files after formatting the data in it. I may be wrong.

Report •

June 19, 2012 at 20:16:50
✔ Best Answer
Yes, you're right about needing a for-loop, i believe.

@echo off & setlocalenabledelayedexpansion
:rem assumed extension applied is .AWK to foll var.
set FormatFile=FORMAT
:ie: FORMAT.AWK will be the awk script...
:and please don't throw a bunch of lfn-with-specchars bs into this soup! GOD!!
set FileLocation=c:\source
set dest=d:\dest
for /f "tokens=1* %%a in ('dir /b %FileLocation%\file*.dat) do (
GAWK -f %FormatFile%.AWK %FileLocation%\%%a(%%b > %FileLocation%\%%aAwked(%%b
UNTESTED! run non-destructive tests to confirm performance!
personal rant not related to post: GOD I HATE MS for the lfn bulls---, ESP. spaces!

Report •

Related Solutions

Ask Question