Re:Header and Footer

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
abhishekkumarrai3
Posts: 12
Joined: 25 Aug 2016 04:20

Re:Header and Footer

#1 Post by abhishekkumarrai3 » 25 Aug 2016 04:23

Hi All,

We have the following requirement and we need your expertise on the same…

• We need to add Header and Trailer

HDR|zem0c15cst|xxx|yyyymmddhhmiss|

Here zem0c15cst - File name

xxx = cycle number, starts at 001, increments by 1 for every cycle.
for ex : if in Folder we have 10 file then for first file XXX = 001
for 2nd file XXX= 002

and here yyyymmddhhmiss --- System Date and Time

TRL|zem0c15cst|CNT|

CNT = Total record count of the file excluding the Header and the Trailer

for Ex: if 3rd file has data

1101|MUM|2002|DELHI
1102|MUM|2002|MUMBAI

so output will be like

HDR|zem0c15cst|003||20160825104210|
1101|MUM|2002|DELHI
1102|MUM|2002|MUMBAI
TRL|zem0c15cst|2|

And Here each file data should store in separate file

Please any one help writing the script in Windows batch script for the above requirement

Help would be appreciated!

Thanks
Abhishek
Last edited by abhishekkumarrai3 on 25 Aug 2016 11:19, edited 3 times in total.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Re:Header and Footer

#2 Post by foxidrive » 25 Aug 2016 04:57

Your question has poor information. See here: viewtopic.php?f=3&t=6108

abhishekkumarrai3
Posts: 12
Joined: 25 Aug 2016 04:20

Re: Re:Header and Footer

#3 Post by abhishekkumarrai3 » 25 Aug 2016 05:51

Hi i have edited the question kindly please check and help me for same

let me know for any question.

Thanks in Advance

Abhishek

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Re:Header and Footer

#4 Post by Squashman » 25 Aug 2016 07:23

How are we supposed to know what the current cycle number is?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Re:Header and Footer

#5 Post by foxidrive » 25 Aug 2016 10:16

Squashman is telling you that your information is still inadequate to understand the details of your file and where the numbers all all taken from.

For example: your date/time string requirement has no information about where this is taken from and what time is meant to be used.

Providing good information about your task makes it easier to help you.

abhishekkumarrai3
Posts: 12
Joined: 25 Aug 2016 04:20

Re: Re:Header and Footer

#6 Post by abhishekkumarrai3 » 25 Aug 2016 11:21

Hi Squashman and Foxidrive

i am sorry for inconvenience, i have updated the information

kindly please check and help me for same.

please let me know if you need more clarification.

Thanks,
Abhishek

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Re:Header and Footer

#7 Post by aGerman » 25 Aug 2016 13:27

Contain those files (like "zem0c15cst") plain text only? (Note: Batch cannot process Excel or data bases)
Are the | characters the separators as you would find them if you open the file in Notepad.exe?

Steffen

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Re:Header and Footer

#8 Post by Aacini » 25 Aug 2016 19:22

Your question is confusing and there are several details missing: Have the files to process .txt extension? What is the format displayed by DATE command in your computer? Should this program run in other computers? Why do you call "cycle" a "file"?

The code below process all *.txt files in current folder and generate output files with .out extension; generated files will all have the same time stamp. It assumes that ECHO %DATE% show "MM/DD/YYYY" and that ECHO %TIME% show "HH:MM:SS.CC".

Code: Select all

@echo off
setlocal EnableDelayedExpansion

rem Get the time stamp
for /F "tokens=1-6 delims=/:." %%a in ("%DATE%/%TIME%") do (
   set "timeStamp=%%c%%a%%b%%d%%e%%f"
)

rem Process all *.txt files
set "cycle=1000"
for %%a in (*.txt) do (

   rem Get cycle number, starts at 001, increments by 1 for every cycle.
   set /A cycle+=1

   rem Get record count
   for /F %%b in ('find /C /V "" ^< "%%a"') do set "count=%%b"

   rem Create the output file
   (
   echo HDR^|%%~Na^|!cycle:~1!^|%timeStamp%^|
   type "%%a"
   echo TRL^|%%~Na^|!count!^|
   ) > "%%~Na.out"
)

Antonio

abhishekkumarrai3
Posts: 12
Joined: 25 Aug 2016 04:20

Re: Re:Header and Footer

#9 Post by abhishekkumarrai3 » 25 Aug 2016 23:47

Hi Antonio/Aacini,

its really AWESOME....:)

Now just little more help in this ....

*That it should search in folder only those file which has name starting with "zem0c15cst"

* And here input and output file will be .dat format

and here the Header part will be like

HDR|zem0c15cst|002|20160826111426|

in my stystem timestamp is 2016-08-26

* and Trailer should print in next line

* And output should print in different folder.

Kindly please help i am new to batch script so asking more help

Help would be appreciated!

Thanks
Abhishek

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Re:Header and Footer

#10 Post by Squashman » 26 Aug 2016 07:55

abhishekkumarrai3 wrote:*That it should search in folder only those file which has name starting with "zem0c15cst"

This tells me that you are not even making an attempt to understand how the code that was given to you works.

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Re:Header and Footer

#11 Post by Aacini » 26 Aug 2016 09:04

abhishekkumarrai3 wrote:Hi Antonio/Aacini,

its really AWESOME....:)

Now just little more help in this ....


In the first reply of this thread you received an advice that the question has poor information, and a link was included to this explanation:

at this post foxidrive wrote:What happens in a thread when incorrect or poor details are supplied: is that the volunteers write a script based upon that information and the next post often comes from the question writer saying "It doesn't work!"

Often a very long series of posts begins where we try to ascertain what the problem is and how the code fails and then what the real details of the task are. The script has to be rewritten, and that just wastes the time of those volunteers who are giving you free code and it is terribly frustrating and unsatisfying for volunteers to have to re-write a script for the same task again.

Don't do this.

Why you didn't read it?

I am afraid that if I fix these new details your next reply will be: "Perfect. Now the next requirements are ...". Sorry...

Antonio

PS - Hint: check that the last line in your input files ends in <CR><LF>.

Post Reply