groupby and spliting

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
santhosh
Posts: 41
Joined: 02 Aug 2010 05:10

groupby and spliting

#1 Post by santhosh » 17 Mar 2011 03:06

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

ghostmachine4
Posts: 319
Joined: 12 May 2006 01:13

Re: groupby and spliting

#2 Post by ghostmachine4 » 17 Mar 2011 03:33

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?

santhosh
Posts: 41
Joined: 02 Aug 2010 05:10

Re: groupby and spliting

#3 Post by santhosh » 19 Mar 2011 06:08

no...i want output like that...

ghostmachine4
Posts: 319
Joined: 12 May 2006 01:13

Re: groupby and spliting

#4 Post by ghostmachine4 » 19 Mar 2011 09:39

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

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: groupby and spliting

#5 Post by dbenham » 07 Apr 2011 16:26

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:

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

santhosh
Posts: 41
Joined: 02 Aug 2010 05:10

Re: groupby and spliting

#6 Post by santhosh » 02 May 2011 22:34

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.

Post Reply