Re:Header and Footer
Moderator: DosItHelp
-
- Posts: 12
- Joined: 25 Aug 2016 04:20
Re:Header and Footer
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
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.
Re: Re:Header and Footer
Your question has poor information. See here: viewtopic.php?f=3&t=6108
-
- Posts: 12
- Joined: 25 Aug 2016 04:20
Re: Re:Header and Footer
Hi i have edited the question kindly please check and help me for same
let me know for any question.
Thanks in Advance
Abhishek
let me know for any question.
Thanks in Advance
Abhishek
Re: Re:Header and Footer
How are we supposed to know what the current cycle number is?
Re: Re:Header and Footer
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.
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.
-
- Posts: 12
- Joined: 25 Aug 2016 04:20
Re: Re:Header and Footer
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
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
Re: Re:Header and Footer
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
Are the | characters the separators as you would find them if you open the file in Notepad.exe?
Steffen
Re: Re:Header and Footer
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".
Antonio
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
-
- Posts: 12
- Joined: 25 Aug 2016 04:20
Re: Re:Header and Footer
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
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
Re: Re:Header and Footer
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.
Re: Re:Header and Footer
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>.