Add a field between lines
Add a field between lines
am 26.11.2007 22:08:23 von CSGill
I have output similar to the following:
==============
0.0 1.3 4325 infodba /opt/
0.0 1.3 4949 infodba /opt/
0.0 1.2 1671 infodba /opt/
0.0 1.5 19471 infodba /opt/
1.2 1.5 23268 infodba /opt/
0.0 2.6 73 infodba /opt/
0.0 1.4 3752 infodba /opt/
0.0 1.5 12378 infodba /opt/
==============
0.0 1.3 4325 infodba /opt/
0.0 1.3 4949 infodba /opt/
0.0 1.2 1671 infodba /opt/
0.0 1.5 19471 infodba /opt/
1.2 1.5 23268 infodba /opt/
0.0 2.6 73 infodba /opt/
0.0 1.4 3752 infodba /opt/
0.0 1.5 12378 infodba /opt/
===============
Would like to sum the first field in each line between the "==" lines
and output to a seperate file each on a new line... similar to:
================
6
================
4
Any help? I think awk is the way to go, but am by no means expert
enough in awk to figure it out...
TIA
Re: Add a field between lines
am 26.11.2007 22:31:38 von Ed Morton
On 11/26/2007 3:08 PM, CGill wrote:
> I have output similar to the following:
>
> ==============
> 0.0 1.3 4325 infodba /opt/
> 0.0 1.3 4949 infodba /opt/
> 0.0 1.2 1671 infodba /opt/
> 0.0 1.5 19471 infodba /opt/
> 1.2 1.5 23268 infodba /opt/
> 0.0 2.6 73 infodba /opt/
> 0.0 1.4 3752 infodba /opt/
> 0.0 1.5 12378 infodba /opt/
> ==============
> 0.0 1.3 4325 infodba /opt/
> 0.0 1.3 4949 infodba /opt/
> 0.0 1.2 1671 infodba /opt/
> 0.0 1.5 19471 infodba /opt/
> 1.2 1.5 23268 infodba /opt/
> 0.0 2.6 73 infodba /opt/
> 0.0 1.4 3752 infodba /opt/
> 0.0 1.5 12378 infodba /opt/
> ===============
>
> Would like to sum the first field in each line between the "==" lines
> and output to a seperate file each on a new line... similar to:
"similar to"?
> ================
> 6
> ================
> 4
>
>
> Any help? I think awk is the way to go, but am by no means expert
> enough in awk to figure it out...
>
> TIA
This should get you close:
awk '
/^=/ { if (c) print tot > "file" c; c++; tot=0; next }
{ tot += $1 }
' file
Regards,
Ed.
Re: Add a field between lines
am 26.11.2007 22:48:53 von CSGill
On Nov 26, 3:31 pm, Ed Morton wrote:
> On 11/26/2007 3:08 PM, CGill wrote:
>
>
>
>
>
> > I have output similar to the following:
>
> > ==============
> > 0.0 1.3 4325 infodba /opt/
> > 0.0 1.3 4949 infodba /opt/
> > 0.0 1.2 1671 infodba /opt/
> > 0.0 1.5 19471 infodba /opt/
> > 1.2 1.5 23268 infodba /opt/
> > 0.0 2.6 73 infodba /opt/
> > 0.0 1.4 3752 infodba /opt/
> > 0.0 1.5 12378 infodba /opt/
> > ==============
> > 0.0 1.3 4325 infodba /opt/
> > 0.0 1.3 4949 infodba /opt/
> > 0.0 1.2 1671 infodba /opt/
> > 0.0 1.5 19471 infodba /opt/
> > 1.2 1.5 23268 infodba /opt/
> > 0.0 2.6 73 infodba /opt/
> > 0.0 1.4 3752 infodba /opt/
> > 0.0 1.5 12378 infodba /opt/
> > ===============
>
> > Would like to sum the first field in each line between the "==" lines
> > and output to a seperate file each on a new line... similar to:
>
> "similar to"?
>
> > ================
> > 6
> > ================
> > 4
>
> > Any help? I think awk is the way to go, but am by no means expert
> > enough in awk to figure it out...
>
> > TIA
>
> This should get you close:
>
> awk '
> /^=/ { if (c) print tot > "file" c; c++; tot=0; next }
> { tot += $1 }
> ' file
>
> Regards,
>
> Ed.- Hide quoted text -
>
> - Show quoted text -
works well... just needed to switch the > to >> inside the brackets as
i don't want a bajillion files :)
Thanks!
Re: Add a field between lines
am 26.11.2007 22:50:12 von CSGill
On Nov 26, 3:31 pm, Ed Morton wrote:
> On 11/26/2007 3:08 PM, CGill wrote:
>
>
>
>
>
> > I have output similar to the following:
>
> > ==============
> > 0.0 1.3 4325 infodba /opt/
> > 0.0 1.3 4949 infodba /opt/
> > 0.0 1.2 1671 infodba /opt/
> > 0.0 1.5 19471 infodba /opt/
> > 1.2 1.5 23268 infodba /opt/
> > 0.0 2.6 73 infodba /opt/
> > 0.0 1.4 3752 infodba /opt/
> > 0.0 1.5 12378 infodba /opt/
> > ==============
> > 0.0 1.3 4325 infodba /opt/
> > 0.0 1.3 4949 infodba /opt/
> > 0.0 1.2 1671 infodba /opt/
> > 0.0 1.5 19471 infodba /opt/
> > 1.2 1.5 23268 infodba /opt/
> > 0.0 2.6 73 infodba /opt/
> > 0.0 1.4 3752 infodba /opt/
> > 0.0 1.5 12378 infodba /opt/
> > ===============
>
> > Would like to sum the first field in each line between the "==" lines
> > and output to a seperate file each on a new line... similar to:
>
> "similar to"?
>
> > ================
> > 6
> > ================
> > 4
>
> > Any help? I think awk is the way to go, but am by no means expert
> > enough in awk to figure it out...
>
> > TIA
>
> This should get you close:
>
> awk '
> /^=/ { if (c) print tot > "file" c; c++; tot=0; next }
> { tot += $1 }
> ' file
>
> Regards,
>
> Ed.- Hide quoted text -
>
> - Show quoted text -
apparently it wasn't that easy... as i'm still getting a million
files... ideas?
Re: Add a field between lines
am 26.11.2007 22:59:43 von Ed Morton
On 11/26/2007 3:50 PM, CGill wrote:
> On Nov 26, 3:31 pm, Ed Morton wrote:
>
>>On 11/26/2007 3:08 PM, CGill wrote:
>>
>>
>>
>>
>>
>>
>>>I have output similar to the following:
>>
>>>==============
>>>0.0 1.3 4325 infodba /opt/
>>>0.0 1.3 4949 infodba /opt/
>>>0.0 1.2 1671 infodba /opt/
>>>0.0 1.5 19471 infodba /opt/
>>>1.2 1.5 23268 infodba /opt/
>>>0.0 2.6 73 infodba /opt/
>>>0.0 1.4 3752 infodba /opt/
>>>0.0 1.5 12378 infodba /opt/
>>>==============
>>>0.0 1.3 4325 infodba /opt/
>>>0.0 1.3 4949 infodba /opt/
>>>0.0 1.2 1671 infodba /opt/
>>>0.0 1.5 19471 infodba /opt/
>>>1.2 1.5 23268 infodba /opt/
>>>0.0 2.6 73 infodba /opt/
>>>0.0 1.4 3752 infodba /opt/
>>>0.0 1.5 12378 infodba /opt/
>>>===============
>>
>>>Would like to sum the first field in each line between the "==" lines
>>>and output to a seperate file each on a new line... similar to:
>>
>>"similar to"?
>>
>>
>>>================
>>>6
>>>================
>>>4
>>
>>>Any help? I think awk is the way to go, but am by no means expert
>>>enough in awk to figure it out...
>>
>>>TIA
>>
>>This should get you close:
>>
>>awk '
>>/^=/ { if (c) print tot > "file" c; c++; tot=0; next }
>>{ tot += $1 }
>>' file
>>
>>Regards,
>>
>> Ed.- Hide quoted text -
>>
>>- Show quoted text -
>
> works well... just needed to switch the > to >> inside the brackets as
> i don't want a bajillion files :)
">" and ">>" don't mean the same thing in awk as they do in shell. In any case,
what I posted will only create one file per block as the print only gets hit on
a line starting with "=".
> apparently it wasn't that easy... as i'm still getting a million
> files... ideas?
Oh, hang on. By this:
>>>Would like to sum the first field in each line between the "==" lines
>>>and output to a seperate file each on a new line...
I thought you were saying that you wanted each sum to be output to a separate
file. If you want them all in one file, change it to this:
awk '
/^=/ { if (tot != "") print $0 ORS tot; tot=0; next }
{ tot += $1 }
' infile > outfile
Ed.
Re: Add a field between lines
am 27.11.2007 06:40:36 von CSGill
On Nov 26, 3:59 pm, Ed Morton wrote:
> On 11/26/2007 3:50 PM, CGill wrote:
>
>
>
>
>
> > On Nov 26, 3:31 pm, Ed Morton wrote:
>
> >>On 11/26/2007 3:08 PM, CGill wrote:
>
> >>>I have output similar to the following:
>
> >>>==============
> >>>0.0 1.3 4325 infodba /opt/
> >>>0.0 1.3 4949 infodba /opt/
> >>>0.0 1.2 1671 infodba /opt/
> >>>0.0 1.5 19471 infodba /opt/
> >>>1.2 1.5 23268 infodba /opt/
> >>>0.0 2.6 73 infodba /opt/
> >>>0.0 1.4 3752 infodba /opt/
> >>>0.0 1.5 12378 infodba /opt/
> >>>==============
> >>>0.0 1.3 4325 infodba /opt/
> >>>0.0 1.3 4949 infodba /opt/
> >>>0.0 1.2 1671 infodba /opt/
> >>>0.0 1.5 19471 infodba /opt/
> >>>1.2 1.5 23268 infodba /opt/
> >>>0.0 2.6 73 infodba /opt/
> >>>0.0 1.4 3752 infodba /opt/
> >>>0.0 1.5 12378 infodba /opt/
> >>>===============
>
> >>>Would like to sum the first field in each line between the "==" lines
> >>>and output to a seperate file each on a new line... similar to:
>
> >>"similar to"?
>
> >>>================
> >>>6
> >>>================
> >>>4
>
> >>>Any help? I think awk is the way to go, but am by no means expert
> >>>enough in awk to figure it out...
>
> >>>TIA
>
> >>This should get you close:
>
> >>awk '
> >>/^=/ { if (c) print tot > "file" c; c++; tot=0; next }
> >>{ tot += $1 }
> >>' file
>
> >>Regards,
>
> >> Ed.- Hide quoted text -
>
> >>- Show quoted text -
>
> > works well... just needed to switch the > to >> inside the brackets as
> > i don't want a bajillion files :)
>
> ">" and ">>" don't mean the same thing in awk as they do in shell. In any case,
> what I posted will only create one file per block as the print only gets hit on
> a line starting with "=".
>
> > apparently it wasn't that easy... as i'm still getting a million
> > files... ideas?
>
> Oh, hang on. By this:
>
> >>>Would like to sum the first field in each line between the "==" lines
> >>>and output to a seperate file each on a new line...
>
> I thought you were saying that you wanted each sum to be output to a separate
> file. If you want them all in one file, change it to this:
>
> awk '
> /^=/ { if (tot != "") print $0 ORS tot; tot=0; next }
> { tot += $1 }
> ' infile > outfile
>
> Ed.- Hide quoted text -
>
> - Show quoted text -
Much obliged....