Hi,
I have this sample data(from cobol fd)
pic(13)v99
x(14)v99
pic(8)
pic(9)v99
like...... it runs into 300 lines...
i want to calculate the characters per field used and upto the line...
from the above i want an output like this..
--------------
ln totupto
-------------
15 15
16 31
8 39
11 50
.......
tha is I want to pickup the number in the brackets add with the
decimal chars. For the first line it is 13+2=15 and each line is
summed upto that line
i wrote code like this...
awk -F"(" '{print $2}' .........but it gave the result as
13)v99
14)v99
8)
9)v99
|
|
0
|
|
|
|
Reply
|
nag
|
4/15/2009 2:58:57 AM |
|
On Apr 14, 9:58=A0pm, nag <visit...@gmail.com> wrote:
> Hi,
>
> I have this sample data(from cobol fd)
> pic(13)v99
> x(14)v99
> pic(8)
> pic(9)v99
> like...... it runs into 300 lines...
>
> i want to calculate the characters per field used and upto the line...
>
> from the above i want an output like this..
> --------------
> ln =A0 totupto
> -------------
> 15 =A0 15
> 16 =A0 31
> 8 =A0 =A0 39
> 11 =A0 50
> ......
>
> tha is I want to pickup the number in the brackets add with the
> decimal chars. For the first line it is 13+2=3D15 and each line is
> summed upto that line
>
> i wrote code like this...
>
> awk -F"(" '{print $2}' .........but it gave the result as
>
> 13)v99
> 14)v99
> 8)
> 9)v99
awk -F '[^[:digit:]]+' '{ln=3D$2+length($3); tot+=3Dln; print ln,tot}' file
|
|
0
|
|
|
|
Reply
|
Ed
|
4/15/2009 12:33:17 PM
|
|
nag escribi�:
> Hi,
>
> I have this sample data(from cobol fd)
> pic(13)v99
> x(14)v99
> pic(8)
> pic(9)v99
> like...... it runs into 300 lines...
>
> i want to calculate the characters per field used and upto the line...
>
> from the above i want an output like this..
> --------------
> ln totupto
> -------------
> 15 15
> 16 31
> 8 39
> 11 50
> ......
>
>
> that is I want to pickup the number in the brackets add with the
> decimal chars. For the first line it is 13+2=15 and each line is
> summed upto that line
>
> i wrote code like this...
>
> awk -F"(" '{print $2}' .........but it gave the result as
>
> 13)v99
> 14)v99
> 8)
> 9)v99
Please try:
BEGIN { FS="[()]" }
{
digits = match($NF,/[0-9]+/) ? RLENGTH : 0
print $2 "+" digits, field=$2+digits, line+=field
}
With your data, it gives:
13+2 15 15
14+2 16 31
8+0 8 39
9+2 11 50
--
Manuel Collado - http://lml.ls.fi.upm.es/~mcollado
|
|
0
|
|
|
|
Reply
|
m
|
4/15/2009 12:33:35 PM
|
|
On Apr 15, 5:33=A0pm, Ed Morton <mortons...@gmail.com> wrote:
> On Apr 14, 9:58=A0pm, nag <visit...@gmail.com> wrote:
>
>
>
> > Hi,
>
> > I have this sample data(from cobol fd)
> > pic(13)v99
> > x(14)v99
> > pic(8)
> > pic(9)v99
> > like...... it runs into 300 lines...
>
> > i want to calculate the characters per field used and upto the line...
>
> > from the above i want an output like this..
> > --------------
> > ln =A0 totupto
> > -------------
> > 15 =A0 15
> > 16 =A0 31
> > 8 =A0 =A0 39
> > 11 =A0 50
> > ......
>
> > tha is I want to pickup the number in the brackets add with the
> > decimal chars. For the first line it is 13+2=3D15 and each line is
> > summed upto that line
>
> > i wrote code like this...
>
> > awk -F"(" '{print $2}' .........but it gave the result as
>
> > 13)v99
> > 14)v99
> > 8)
> > 9)v99
>
> awk -F '[^[:digit:]]+' '{ln=3D$2+length($3); tot+=3Dln; print ln,tot}' fi=
le
what the field separator tells here ([:digit:]]+ ). The + sign for
what?
|
|
0
|
|
|
|
Reply
|
nag
|
4/15/2009 4:52:03 PM
|
|
Wed, 15 Apr 2009 09:52:03 -0700, nag did cat :
> On Apr 15, 5:33 pm, Ed Morton <mortons...@gmail.com> wrote:
>> On Apr 14, 9:58 pm, nag <visit...@gmail.com> wrote:
>>
>>
>>
>> > Hi,
>>
>> > I have this sample data(from cobol fd) pic(13)v99
>> > x(14)v99
>> > pic(8)
>> > pic(9)v99
>> > like...... it runs into 300 lines...
>>
>> > i want to calculate the characters per field used and upto the
>> > line...
>>
>> > from the above i want an output like this.. --------------
>> > ln totupto
>> > -------------
>> > 15 15
>> > 16 31
>> > 8 39
>> > 11 50
>> > ......
>>
>> > tha is I want to pickup the number in the brackets add with the
>> > decimal chars. For the first line it is 13+2=15 and each line is
>> > summed upto that line
>>
>> > i wrote code like this...
>>
>> > awk -F"(" '{print $2}' .........but it gave the result as
>>
>> > 13)v99
>> > 14)v99
>> > 8)
>> > 9)v99
>>
>> awk -F '[^[:digit:]]+' '{ln=$2+length($3); tot+=ln; print ln,tot}' file
>
> what the field separator tells here ([:digit:]]+ ). The + sign for what?
the plus is a repeater, means "one or more iterations of previous group"
the group here is "any non digit"
in the given example that's akin to:
awk -F '[()v]+'
|
|
0
|
|
|
|
Reply
|
Loki
|
4/15/2009 4:59:56 PM
|
|
On Apr 15, 5:33=A0pm, m.coll...@domain.invalid wrote:
> nag escribi=F3:
>
>
>
> > Hi,
>
> > I have this sample data(from cobol fd)
> > pic(13)v99
> > x(14)v99
> > pic(8)
> > pic(9)v99
> > like...... it runs into 300 lines...
>
> > i want to calculate the characters per field used and upto the line...
>
> > from the above i want an output like this..
> > --------------
> > ln =A0 totupto
> > -------------
> > 15 =A0 15
> > 16 =A0 31
> > 8 =A0 =A0 39
> > 11 =A0 50
> > ......
>
> > that is I want to pickup the number in the brackets add with the
> > decimal chars. For the first line it is 13+2=3D15 and each line is
> > summed upto that line
>
> > i wrote code like this...
>
> > awk -F"(" '{print $2}' .........but it gave the result as
>
> > 13)v99
> > 14)v99
> > 8)
> > 9)v99
>
> Please try:
>
> BEGIN { FS=3D"[()]" }
> {
> =A0 =A0 digits =3D match($NF,/[0-9]+/) ? RLENGTH : 0
> =A0 =A0 print $2 "+" digits, field=3D$2+digits, line+=3Dfield
>
> }
>
> With your data, it gives:
>
> 13+2 15 15
> 14+2 16 31
> 8+0 8 39
> 9+2 11 50
>
> --
> Manuel Collado -http://lml.ls.fi.upm.es/~mcollado
Thank you alot it gave me required result...
but here when you are defining FS =3D "[()]", i understood that here fs
is (), then how it is taking the digits in the brackets as $2?
|
|
0
|
|
|
|
Reply
|
nag
|
4/16/2009 12:05:40 AM
|
|
nag wrote:
> On Apr 15, 5:33 pm, m.coll...@domain.invalid wrote:
>
>>nag escribi�:
>>
>>
>>
>>
>>>Hi,
>>
>>>I have this sample data(from cobol fd)
>>>pic(13)v99
>>>x(14)v99
>>>pic(8)
>>>pic(9)v99
>>>like...... it runs into 300 lines...
>>
>>>i want to calculate the characters per field used and upto the line...
>>
>>>from the above i want an output like this..
>>>--------------
>>>ln totupto
>>>-------------
>>>15 15
>>>16 31
>>>8 39
>>>11 50
>>>......
>>
>>>that is I want to pickup the number in the brackets add with the
>>>decimal chars. For the first line it is 13+2=15 and each line is
>>>summed upto that line
>>
>>>i wrote code like this...
>>
>>>awk -F"(" '{print $2}' .........but it gave the result as
>>
>>>13)v99
>>>14)v99
>>>8)
>>>9)v99
>>
>>Please try:
>>
>>BEGIN { FS="[()]" }
>>{
>> digits = match($NF,/[0-9]+/) ? RLENGTH : 0
>> print $2 "+" digits, field=$2+digits, line+=field
>>
>>}
>>
>>With your data, it gives:
>>
>>13+2 15 15
>>14+2 16 31
>>8+0 8 39
>>9+2 11 50
>>
>>--
>>Manuel Collado -http://lml.ls.fi.upm.es/~mcollado
>
>
> Thank you alot it gave me required result...
>
> but here when you are defining FS = "[()]", i understood that here fs
> is (),
No. Here FS is either ( or ).
> then how it is taking the digits in the brackets as $2?
For example, in pic(13)v99 you have two delimiters, ( and ), that
separate the parts 'pic' ($1), '12' ($2), and v99 ($3).
Janis
|
|
0
|
|
|
|
Reply
|
Janis
|
4/16/2009 12:09:53 AM
|
|
|
6 Replies
272 Views
(page loaded in 0.126 seconds)
|