hi,
anyone help me out to find this.
input file:-
date series err count
07 002348 149 [1]
07 002348 254 [1]
07 002348 0 [1]
08 002203 0 [2]
08 002347 0 [2]
08 002347 149 [1]
08 002348 148 [1]
08 002348 149 [2]
output:-
date series ecount scount
07 002348 5 1
08 002203 0 2
08 002347 1 2
using awk tool
thanks in advance
groupby and spliting
Moderator: DosItHelp
-
- Posts: 319
- Joined: 12 May 2006 01:13
Re: groupby and spliting
santhosh wrote:hi,
anyone help me out to find this.
input file:-
date series err count
07 002348 149 [1]
07 002348 254 [1]
07 002348 0 [1]
08 002203 0 [2]
08 002347 0 [2]
08 002347 149 [1]
08 002348 148 [1]
08 002348 149 [2]
output:-
date series ecount scount
07 002348 5 1
08 002203 0 2
08 002347 1 2
using awk tool
thanks in advance
and you expect us to guess how you got that output?
Re: groupby and spliting
no...i want output like that...
-
- Posts: 319
- Joined: 12 May 2006 01:13
Re: groupby and spliting
santhosh wrote:no...i want output like that...
so you want it to be like that, but you are not telling us how you got that output. You expect us to guess what you want ? you are not going to get much help unless you define and explain your problem more clearly
Re: groupby and spliting
Assuming:
input data is in input.txt in current directory
output goes to output.txt in current directory
an err code of 0=succcess, any other value=error
output:
grouped by series
date = earliest date series appeared
ecount = error count = sum of count with err<>0
scount = success count = sum of count with err=0
output should be sorted by earliest appearance date, then by series
then the following should work:
I'm sure you would have gotten a faster response had you given some more explanation
Dave
input data is in input.txt in current directory
output goes to output.txt in current directory
an err code of 0=succcess, any other value=error
output:
grouped by series
date = earliest date series appeared
ecount = error count = sum of count with err<>0
scount = success count = sum of count with err=0
output should be sorted by earliest appearance date, then by series
then the following should work:
Code: Select all
@echo off
setlocal enableDelayedExpansion
set ser=x
if exist temp.txt del temp.txt
for /f "tokens=1-4 delims=[] " %%a in ('type input.txt ^| sort /+4') do (
if not %%b==!ser! (
if not !ser!==x echo !dt! !ser! !ecnt! !scnt!>>temp.txt
set /a ecnt=0, scnt=0
set dt=%%a
set ser=%%b
)
if %%a lss !dt! set dt=%%a
if %%c==0 (set /a scnt+=%%d) else set /a ecnt+=%%d
)
echo date series ecount scount>output.txt
type temp.txt | sort>>output.txt
del temp.txt
I'm sure you would have gotten a faster response had you given some more explanation
Dave
Re: groupby and spliting
hi dbenham,
Thanks for your response i didnt tested it, but i did in shell scripting its working fine........i will try it and say in DOS.
Thanks for your response i didnt tested it, but i did in shell scripting its working fine........i will try it and say in DOS.