Page 1 of 1

groupby and spliting

Posted: 17 Mar 2011 03:06
by santhosh
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

Re: groupby and spliting

Posted: 17 Mar 2011 03:33
by ghostmachine4
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

Posted: 19 Mar 2011 06:08
by santhosh
no...i want output like that...

Re: groupby and spliting

Posted: 19 Mar 2011 09:39
by ghostmachine4
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

Posted: 07 Apr 2011 16:26
by dbenham
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

Re: groupby and spliting

Posted: 02 May 2011 22:34
by santhosh
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.