Arithmatic operation

hello ,

i have a file called abc.txt , contain of this file is
# more abc.txt
1
2
34
45
65
.......
Now i want to take one value and perform arithmatic operation for that
i have created following script but its not working , i'm using ksh

#script1
FIX=1024
for i in `cat abc.txt`
do
length1=`expr $i / 2`
length2=`expr $length1 / $FIX`
length3=`expr $length2 / $FIX`
done >> op

would be appricate to help me out to resolve the problem also suggest
me the short and sweet way of this script ,if any one having idea.
i am converting values in GB

thanks

Nikunj
Nikunj [ Mo, 03 Dezember 2007 17:54 ] [ ID #1884302 ]

Re: Arithmatic operation

On 12/3/2007 10:54 AM, Nikunj wrote:
> hello ,
>
> i have a file called abc.txt , contain of this file is
> # more abc.txt
> 1
> 2
> 34
> 45
> 65
> ......
> Now i want to take one value and perform arithmatic operation for that
> i have created following script but its not working , i'm using ksh
>
> #script1
> FIX=1024
> for i in `cat abc.txt`
> do
> length1=`expr $i / 2`
> length2=`expr $length1 / $FIX`
> length3=`expr $length2 / $FIX`
> done >> op
>
> would be appricate to help me out to resolve the problem also suggest
> me the short and sweet way of this script ,if any one having idea.
> i am converting values in GB
>
> thanks
>
> Nikunj

You don't show what you want the output to be. If it's just the final result of
the arithmetic ops, then all you need is:

awk 'BEGIN{fix=1024;div=2*fix*fix} {print $0 / div}' abc.txt > op

Regards,

Ed.
Ed Morton [ Mo, 03 Dezember 2007 18:10 ] [ ID #1884305 ]

Re: Arithmatic operation

On Dec 3, 11:10 am, Ed Morton <mor... [at] lsupcaemnt.com> wrote:
> On 12/3/2007 10:54 AM, Nikunj wrote:
>
>
>
>
>
> > hello ,
>
> > i have a file called abc.txt , contain of this file is
> > # more abc.txt
> > 1
> > 2
> > 34
> > 45
> > 65
> > ......
> > Now i want to take one value and perform arithmatic operation for that
> > i have created following script but its not working , i'm using ksh
>
> > #script1
> > FIX=1024
> > for i in `cat abc.txt`
> > do
> > length1=`expr $i / 2`
> > length2=`expr $length1 / $FIX`
> > length3=`expr $length2 / $FIX`
> > done >> op
>
> > would be appricate to help me out to resolve the problem also suggest
> > me the short and sweet way of this script ,if any one having idea.
> > i am converting values in GB
>
> > thanks
>
> > Nikunj
>
> You don't show what you want the output to be. If it's just the final result of
> the arithmetic ops, then all you need is:
>
> awk 'BEGIN{fix=1024;div=2*fix*fix} {print $0 / div}' abc.txt > op
>
> Regards,
>
> Ed.- Hide quoted text -
>
> - Show quoted text -
great ....!!!

its very easy way just got it in one line ..

excellent solution ..i have done with the script

thanks ......
Nikunj
Nikunj [ Mo, 03 Dezember 2007 18:36 ] [ ID #1884307 ]

Re: Arithmatic operation

On 2007-12-03, Nikunj <niku.khakhar [at] gmail.com> wrote:
>
>
> hello ,
>
> i have a file called abc.txt , contain of this file is
> # more abc.txt
> 1
> 2
> 34
> 45
> 65
> ......
> Now i want to take one value and perform arithmatic operation for that
> i have created following script but its not working , i'm using ksh
>
> #script1
> FIX=1024
> for i in `cat abc.txt`
> do
> length1=`expr $i / 2`
> length2=`expr $length1 / $FIX`
> length3=`expr $length2 / $FIX`
> done >> op
>
You are just setting variables, not outputting them. Also, instead of
expr you could use the shell's built-in arithmetic:
length=$((i/2))
echo $length
If you want non-integer results, ksh93 and zsh have floating point
arithmetic, or you can use bc or awk.
Bill Marcum [ Mo, 03 Dezember 2007 18:26 ] [ ID #1884309 ]

Re: Arithmatic operation

On Dec 3, 11:10 am, Ed Morton <mor... [at] lsupcaemnt.com> wrote:
> On 12/3/2007 10:54 AM, Nikunj wrote:
>
>
>
>
>
> > hello ,
>
> > i have a file called abc.txt , contain of this file is
> > # more abc.txt
> > 1
> > 2
> > 34
> > 45
> > 65
> > ......
> > Now i want to take one value and perform arithmatic operation for that
> > i have created following script but its not working , i'm using ksh
>
> > #script1
> > FIX=1024
> > for i in `cat abc.txt`
> > do
> > length1=`expr $i / 2`
> > length2=`expr $length1 / $FIX`
> > length3=`expr $length2 / $FIX`
> > done >> op
>
> > would be appricate to help me out to resolve the problem also suggest
> > me the short and sweet way of this script ,if any one having idea.
> > i am converting values in GB
>
> > thanks
>
> > Nikunj
>
> You don't show what you want the output to be. If it's just the final result of
> the arithmetic ops, then all you need is:
>
> awk 'BEGIN{fix=1024;div=2*fix*fix} {print $0 / div}' abc.txt > op
>
> Regards,
>
> Ed.- Hide quoted text -
>
> - Show quoted text -

hey ed,

i got the output in format "15.9911"
i want only 2 dec.point or want in integrer format how can i do ?
Nikunj [ Mo, 03 Dezember 2007 18:57 ] [ ID #1884310 ]

Re: Arithmatic operation

Nikunj wrote:
> hello ,
>
> i have a file called abc.txt , contain of this file is
> # more abc.txt
> 1
> 2
> 34
> 45
> 65
> ......
> Now i want to take one value and perform arithmatic operation for that
> i have created following script but its not working , i'm using ksh
>
> #script1
> FIX=1024
> for i in `cat abc.txt`
> do
> length1=`expr $i / 2`
> length2=`expr $length1 / $FIX`
> length3=`expr $length2 / $FIX`
> done >> op
>
> would be appricate to help me out to resolve the problem also suggest
> me the short and sweet way of this script ,if any one having idea.
> i am converting values in GB
>
> thanks
>
> Nikunj

The ohnly thing wrong is that you never echo the result. Just add

echo $length3
before the "done" line.

-Wayne
wayne [ Mo, 03 Dezember 2007 19:30 ] [ ID #1884311 ]

Re: Arithmatic operation

On 12/3/2007 11:57 AM, Nikunj wrote:
> On Dec 3, 11:10 am, Ed Morton <mor... [at] lsupcaemnt.com> wrote:
>
>>On 12/3/2007 10:54 AM, Nikunj wrote:
>>
>>
>>
>>
>>
>>
>>>hello ,
>>
>>>i have a file called abc.txt , contain of this file is
>>># more abc.txt
>>>1
>>>2
>>>34
>>>45
>>>65
>>>......
>>>Now i want to take one value and perform arithmatic operation for that
>>>i have created following script but its not working , i'm using ksh
>>
>>>#script1
>>>FIX=1024
>>>for i in `cat abc.txt`
>>>do
>>>length1=`expr $i / 2`
>>>length2=`expr $length1 / $FIX`
>>>length3=`expr $length2 / $FIX`
>>>done >> op
>>
>>>would be appricate to help me out to resolve the problem also suggest
>>>me the short and sweet way of this script ,if any one having idea.
>>>i am converting values in GB
>>
>>>thanks
>>
>>>Nikunj
>>
>>You don't show what you want the output to be. If it's just the final result of
>>the arithmetic ops, then all you need is:
>>
>>awk 'BEGIN{fix=1024;div=2*fix*fix} {print $0 / div}' abc.txt > op
>>
>>Regards,
>>
>> Ed.- Hide quoted text -
>>
>>- Show quoted text -
>
>
> hey ed,
>
> i got the output in format "15.9911"
> i want only 2 dec.point or want in integrer format how can i do ?

Something like:

printf "%d\n",$0 / div

printf takes all the normal formatting options you'd expect in C (if that helps).

Ed.
Ed Morton [ Mo, 03 Dezember 2007 20:07 ] [ ID #1884312 ]

Re: Arithmatic operation

On Dec 3, 1:07 pm, Ed Morton <mor... [at] lsupcaemnt.com> wrote:
> On 12/3/2007 11:57 AM, Nikunj wrote:
>
>
>
>
>
> > On Dec 3, 11:10 am, Ed Morton <mor... [at] lsupcaemnt.com> wrote:
>
> >>On 12/3/2007 10:54 AM, Nikunj wrote:
>
> >>>hello ,
>
> >>>i have a file called abc.txt , contain of this file is
> >>># more abc.txt
> >>>1
> >>>2
> >>>34
> >>>45
> >>>65
> >>>......
> >>>Now i want to take one value and perform arithmatic operation for that
> >>>i have created following script but its not working , i'm using ksh
>
> >>>#script1
> >>>FIX=1024
> >>>for i in `cat abc.txt`
> >>>do
> >>>length1=`expr $i / 2`
> >>>length2=`expr $length1 / $FIX`
> >>>length3=`expr $length2 / $FIX`
> >>>done >> op
>
> >>>would be appricate to help me out to resolve the problem also suggest
> >>>me the short and sweet way of this script ,if any one having idea.
> >>>i am converting values in GB
>
> >>>thanks
>
> >>>Nikunj
>
> >>You don't show what you want the output to be. If it's just the final result of
> >>the arithmetic ops, then all you need is:
>
> >>awk 'BEGIN{fix=1024;div=2*fix*fix} {print $0 / div}' abc.txt > op
>
> >>Regards,
>
> >> Ed.- Hide quoted text -
>
> >>- Show quoted text -
>
> > hey ed,
>
> > i got the output in format "15.9911"
> > i want only 2 dec.point or want in integrer format how can i do ?
>
> Something like:
>
> printf "%d\n",$0 / div
>
> printf takes all the normal formatting options you'd expect in C (if that helps).
>
> Ed.- Hide quoted text -
>
> - Show quoted text -

thanks for respond...

where i put it ?

before awk statement or after awk /

Nikunj
Nikunj [ Mo, 03 Dezember 2007 20:26 ] [ ID #1884315 ]

Re: Arithmatic operation

On 12/3/2007 1:26 PM, Nikunj wrote:
> On Dec 3, 1:07 pm, Ed Morton <mor... [at] lsupcaemnt.com> wrote:
>
>>On 12/3/2007 11:57 AM, Nikunj wrote:
>>
>>
>>
>>
>>
>>
>>>On Dec 3, 11:10 am, Ed Morton <mor... [at] lsupcaemnt.com> wrote:
>>
>>>>On 12/3/2007 10:54 AM, Nikunj wrote:
>>>
>>>>>hello ,
>>>>
>>>>>i have a file called abc.txt , contain of this file is
>>>>># more abc.txt
>>>>>1
>>>>>2
>>>>>34
>>>>>45
>>>>>65
>>>>>......
>>>>>Now i want to take one value and perform arithmatic operation for that
>>>>>i have created following script but its not working , i'm using ksh
>>>>
>>>>>#script1
>>>>>FIX=1024
>>>>>for i in `cat abc.txt`
>>>>>do
>>>>>length1=`expr $i / 2`
>>>>>length2=`expr $length1 / $FIX`
>>>>>length3=`expr $length2 / $FIX`
>>>>>done >> op
>>>>
>>>>>would be appricate to help me out to resolve the problem also suggest
>>>>>me the short and sweet way of this script ,if any one having idea.
>>>>>i am converting values in GB
>>>>
>>>>>thanks
>>>>
>>>>>Nikunj
>>>>
>>>>You don't show what you want the output to be. If it's just the final result of
>>>>the arithmetic ops, then all you need is:
>>>
>>>>awk 'BEGIN{fix=1024;div=2*fix*fix} {print $0 / div}' abc.txt > op
>>>
>>>>Regards,
>>>
>>>> Ed.- Hide quoted text -
>>>
>>>>- Show quoted text -
>>>
>>>hey ed,
>>
>>>i got the output in format "15.9911"
>>>i want only 2 dec.point or want in integrer format how can i do ?
>>
>>Something like:
>>
>> printf "%d\n",$0 / div
>>
>>printf takes all the normal formatting options you'd expect in C (if that helps).
>>
>> Ed.- Hide quoted text -
>>
>>- Show quoted text -
>
>
> thanks for respond...
>
> where i put it ?
>
> before awk statement or after awk /

awk 'BEGIN{fix=1024;div=2*fix*fix} {printf "%d\n",$0 / div}' abc.txt > op
Ed Morton [ Mo, 03 Dezember 2007 20:29 ] [ ID #1884316 ]

Re: Arithmatic operation

On Dec 3, 1:29 pm, Ed Morton <mor... [at] lsupcaemnt.com> wrote:
> On 12/3/2007 1:26 PM, Nikunj wrote:
>
>
>
>
>
> > On Dec 3, 1:07 pm, Ed Morton <mor... [at] lsupcaemnt.com> wrote:
>
> >>On 12/3/2007 11:57 AM, Nikunj wrote:
>
> >>>On Dec 3, 11:10 am, Ed Morton <mor... [at] lsupcaemnt.com> wrote:
>
> >>>>On 12/3/2007 10:54 AM, Nikunj wrote:
>
> >>>>>hello ,
>
> >>>>>i have a file called abc.txt , contain of this file is
> >>>>># more abc.txt
> >>>>>1
> >>>>>2
> >>>>>34
> >>>>>45
> >>>>>65
> >>>>>......
> >>>>>Now i want to take one value and perform arithmatic operation for that
> >>>>>i have created following script but its not working , i'm using ksh
>
> >>>>>#script1
> >>>>>FIX=1024
> >>>>>for i in `cat abc.txt`
> >>>>>do
> >>>>>length1=`expr $i / 2`
> >>>>>length2=`expr $length1 / $FIX`
> >>>>>length3=`expr $length2 / $FIX`
> >>>>>done >> op
>
> >>>>>would be appricate to help me out to resolve the problem also suggest
> >>>>>me the short and sweet way of this script ,if any one having idea.
> >>>>>i am converting values in GB
>
> >>>>>thanks
>
> >>>>>Nikunj
>
> >>>>You don't show what you want the output to be. If it's just the final result of
> >>>>the arithmetic ops, then all you need is:
>
> >>>>awk 'BEGIN{fix=1024;div=2*fix*fix} {print $0 / div}' abc.txt > op
>
> >>>>Regards,
>
> >>>> Ed.- Hide quoted text -
>
> >>>>- Show quoted text -
>
> >>>hey ed,
>
> >>>i got the output in format "15.9911"
> >>>i want only 2 dec.point or want in integrer format how can i do ?
>
> >>Something like:
>
> >> printf "%d\n",$0 / div
>
> >>printf takes all the normal formatting options you'd expect in C (if that helps).
>
> >> Ed.- Hide quoted text -
>
> >>- Show quoted text -
>
> > thanks for respond...
>
> > where i put it ?
>
> > before awk statement or after awk /
>
> awk 'BEGIN{fix=1024;div=2*fix*fix} {printf "%d\n",$0 / div}' abc.txt > op- Hide quoted text -
>
> - Show quoted text -

thanks for your prompt response , i've done with it...!!!

reg,
nik
Nikunj [ Mo, 03 Dezember 2007 20:42 ] [ ID #1884317 ]

Re: Arithmatic operation

On Dec 3, 1:42 pm, Nikunj <niku.khak... [at] gmail.com> wrote:
> On Dec 3, 1:29 pm, Ed Morton <mor... [at] lsupcaemnt.com> wrote:
>
>
>
>
>
> > On 12/3/2007 1:26 PM, Nikunj wrote:
>
> > > On Dec 3, 1:07 pm, Ed Morton <mor... [at] lsupcaemnt.com> wrote:
>
> > >>On 12/3/2007 11:57 AM, Nikunj wrote:
>
> > >>>On Dec 3, 11:10 am, Ed Morton <mor... [at] lsupcaemnt.com> wrote:
>
> > >>>>On 12/3/2007 10:54 AM, Nikunj wrote:
>
> > >>>>>hello ,
>
> > >>>>>i have a file called abc.txt , contain of this file is
> > >>>>># more abc.txt
> > >>>>>1
> > >>>>>2
> > >>>>>34
> > >>>>>45
> > >>>>>65
> > >>>>>......
> > >>>>>Now i want to take one value and perform arithmatic operation for that
> > >>>>>i have created following script but its not working , i'm using ksh
>
> > >>>>>#script1
> > >>>>>FIX=1024
> > >>>>>for i in `cat abc.txt`
> > >>>>>do
> > >>>>>length1=`expr $i / 2`
> > >>>>>length2=`expr $length1 / $FIX`
> > >>>>>length3=`expr $length2 / $FIX`
> > >>>>>done >> op
>
> > >>>>>would be appricate to help me out to resolve the problem also suggest
> > >>>>>me the short and sweet way of this script ,if any one having idea.
> > >>>>>i am converting values in GB
>
> > >>>>>thanks
>
> > >>>>>Nikunj
>
> > >>>>You don't show what you want the output to be. If it's just the final result of
> > >>>>the arithmetic ops, then all you need is:
>
> > >>>>awk 'BEGIN{fix=1024;div=2*fix*fix} {print $0 / div}' abc.txt > op
>
> > >>>>Regards,
>
> > >>>> Ed.- Hide quoted text -
>
> > >>>>- Show quoted text -
>
> > >>>hey ed,
>
> > >>>i got the output in format "15.9911"
> > >>>i want only 2 dec.point or want in integrer format how can i do ?
>
> > >>Something like:
>
> > >> printf "%d\n",$0 / div
>
> > >>printf takes all the normal formatting options you'd expect in C (if that helps).
>
> > >> Ed.- Hide quoted text -
>
> > >>- Show quoted text -
>
> > > thanks for respond...
>
> > > where i put it ?
>
> > > before awk statement or after awk /
>
> > awk 'BEGIN{fix=1024;div=2*fix*fix} {printf "%d\n",$0 / div}' abc.txt > op- Hide quoted text -
>
> > - Show quoted text -
>
> thanks for your prompt response , i've done with it...!!!
>
> reg,
> nik- Hide quoted text -
>
> - Show quoted text -

hello ,

thanks all for response


hello i got the output in following format i got dg name twice for
example dg_te1's having 2 output 11 &39 . i want to make it as one
mean i want it dg_te1 50 mean (11+39) . can i do it ...
your help would be appriciated.


dg_te1_Data 14

dg_te1_Data 0

dg_te1 15

dg_te1 11

dg_te1 39

dg_te1 39

Thanks
niks
Nikunj [ Di, 04 Dezember 2007 18:27 ] [ ID #1885029 ]

Re: Arithmatic operation

On 12/4/2007 11:27 AM, Nikunj wrote:
> On Dec 3, 1:42 pm, Nikunj <niku.khak... [at] gmail.com> wrote:
>
>>On Dec 3, 1:29 pm, Ed Morton <mor... [at] lsupcaemnt.com> wrote:
>>
>>
>>
>>
>>
>>
>>>On 12/3/2007 1:26 PM, Nikunj wrote:
>>
>>>>On Dec 3, 1:07 pm, Ed Morton <mor... [at] lsupcaemnt.com> wrote:
>>>
>>>>>On 12/3/2007 11:57 AM, Nikunj wrote:
>>>>
>>>>>>On Dec 3, 11:10 am, Ed Morton <mor... [at] lsupcaemnt.com> wrote:
>>>>>
>>>>>>>On 12/3/2007 10:54 AM, Nikunj wrote:
>>>>>>
>>>>>>>>hello ,
>>>>>>>
>>>>>>>>i have a file called abc.txt , contain of this file is
>>>>>>>># more abc.txt
>>>>>>>>1
>>>>>>>>2
>>>>>>>>34
>>>>>>>>45
>>>>>>>>65
>>>>>>>>......
>>>>>>>>Now i want to take one value and perform arithmatic operation for that
>>>>>>>>i have created following script but its not working , i'm using ksh
>>>>>>>
>>>>>>>>#script1
>>>>>>>>FIX=1024
>>>>>>>>for i in `cat abc.txt`
>>>>>>>>do
>>>>>>>>length1=`expr $i / 2`
>>>>>>>>length2=`expr $length1 / $FIX`
>>>>>>>>length3=`expr $length2 / $FIX`
>>>>>>>>done >> op
>>>>>>>
>>>>>>>>would be appricate to help me out to resolve the problem also suggest
>>>>>>>>me the short and sweet way of this script ,if any one having idea.
>>>>>>>>i am converting values in GB
>>>>>>>
>>>>>>>>thanks
>>>>>>>
>>>>>>>>Nikunj
>>>>>>>
>>>>>>>You don't show what you want the output to be. If it's just the final result of
>>>>>>>the arithmetic ops, then all you need is:
>>>>>>
>>>>>>>awk 'BEGIN{fix=1024;div=2*fix*fix} {print $0 / div}' abc.txt > op
>>>>>>
>>>>>>>Regards,
>>>>>>
>>>>>>> Ed.- Hide quoted text -
>>>>>>
>>>>>>>- Show quoted text -
>>>>>>
>>>>>>hey ed,
>>>>>
>>>>>>i got the output in format "15.9911"
>>>>>>i want only 2 dec.point or want in integrer format how can i do ?
>>>>>
>>>>>Something like:
>>>>
>>>>> printf "%d\n",$0 / div
>>>>
>>>>>printf takes all the normal formatting options you'd expect in C (if that helps).
>>>>
>>>>> Ed.- Hide quoted text -
>>>>
>>>>>- Show quoted text -
>>>>
>>>>thanks for respond...
>>>
>>>>where i put it ?
>>>
>>>>before awk statement or after awk /
>>>
>>>awk 'BEGIN{fix=1024;div=2*fix*fix} {printf "%d\n",$0 / div}' abc.txt > op- Hide quoted text -
>>
>>>- Show quoted text -
>>
>>thanks for your prompt response , i've done with it...!!!
>>
>>reg,
>>nik- Hide quoted text -
>>
>>- Show quoted text -
>
>
> hello ,
>
> thanks all for response
>
>
> hello i got the output in following format i got dg name twice for
> example dg_te1's having 2 output 11 &39 . i want to make it as one
> mean i want it dg_te1 50 mean (11+39) . can i do it ...
> your help would be appriciated.
>
>
> dg_te1_Data 14
>
> dg_te1_Data 0
>
> dg_te1 15
>
> dg_te1 11
>
> dg_te1 39
>
> dg_te1 39
>
> Thanks
> niks

The output you posted doesn't match the input you posted or the script I gave
you and it sounds like your requirements have changed. Start again. Tell us what
you want to do, post sample input, expected output, the script you ran, the
output it gives, and what's wrong with that output.

Ed.
Ed Morton [ Di, 04 Dezember 2007 18:33 ] [ ID #1885030 ]

Re: Arithmatic operation

On Dec 4, 11:33 am, Ed Morton <mor... [at] lsupcaemnt.com> wrote:
> On 12/4/2007 11:27 AM, Nikunj wrote:
>
>
>
>
>
> > On Dec 3, 1:42 pm, Nikunj <niku.khak... [at] gmail.com> wrote:
>
> >>On Dec 3, 1:29 pm, Ed Morton <mor... [at] lsupcaemnt.com> wrote:
>
> >>>On 12/3/2007 1:26 PM, Nikunj wrote:
>
> >>>>On Dec 3, 1:07 pm, Ed Morton <mor... [at] lsupcaemnt.com> wrote:
>
> >>>>>On 12/3/2007 11:57 AM, Nikunj wrote:
>
> >>>>>>On Dec 3, 11:10 am, Ed Morton <mor... [at] lsupcaemnt.com> wrote:
>
> >>>>>>>On 12/3/2007 10:54 AM, Nikunj wrote:
>
> >>>>>>>>hello ,
>
> >>>>>>>>i have a file called abc.txt , contain of this file is
> >>>>>>>># more abc.txt
> >>>>>>>>1
> >>>>>>>>2
> >>>>>>>>34
> >>>>>>>>45
> >>>>>>>>65
> >>>>>>>>......
> >>>>>>>>Now i want to take one value and perform arithmatic operation for that
> >>>>>>>>i have created following script but its not working , i'm using ksh
>
> >>>>>>>>#script1
> >>>>>>>>FIX=1024
> >>>>>>>>for i in `cat abc.txt`
> >>>>>>>>do
> >>>>>>>>length1=`expr $i / 2`
> >>>>>>>>length2=`expr $length1 / $FIX`
> >>>>>>>>length3=`expr $length2 / $FIX`
> >>>>>>>>done >> op
>
> >>>>>>>>would be appricate to help me out to resolve the problem also suggest
> >>>>>>>>me the short and sweet way of this script ,if any one having idea.
> >>>>>>>>i am converting values in GB
>
> >>>>>>>>thanks
>
> >>>>>>>>Nikunj
>
> >>>>>>>You don't show what you want the output to be. If it's just the final result of
> >>>>>>>the arithmetic ops, then all you need is:
>
> >>>>>>>awk 'BEGIN{fix=1024;div=2*fix*fix} {print $0 / div}' abc.txt > op
>
> >>>>>>>Regards,
>
> >>>>>>> Ed.- Hide quoted text -
>
> >>>>>>>- Show quoted text -
>
> >>>>>>hey ed,
>
> >>>>>>i got the output in format "15.9911"
> >>>>>>i want only 2 dec.point or want in integrer format how can i do ?
>
> >>>>>Something like:
>
> >>>>> printf "%d\n",$0 / div
>
> >>>>>printf takes all the normal formatting options you'd expect in C (if that helps).
>
> >>>>> Ed.- Hide quoted text -
>
> >>>>>- Show quoted text -
>
> >>>>thanks for respond...
>
> >>>>where i put it ?
>
> >>>>before awk statement or after awk /
>
> >>>awk 'BEGIN{fix=1024;div=2*fix*fix} {printf "%d\n",$0 / div}' abc.txt > op- Hide quoted text -
>
> >>>- Show quoted text -
>
> >>thanks for your prompt response , i've done with it...!!!
>
> >>reg,
> >>nik- Hide quoted text -
>
> >>- Show quoted text -
>
> > hello ,
>
> > thanks all for response
>
> > hello i got the output in following format i got dg name twice for
> > example dg_te1's having 2 output 11 &39 . i want to make it as one
> > mean i want it dg_te1 50 mean (11+39) . can i do it ...
> > your help would be appriciated.
>
> > dg_te1_Data 14
>
> > dg_te1_Data 0
>
> > dg_te1 15
>
> > dg_te1 11
>
> > dg_te1 39
>
> > dg_te1 39
>
> > Thanks
> > niks
>
> The output you posted doesn't match the input you posted or the script I gave
> you and it sounds like your requirements have changed. Start again. Tell us what
> you want to do, post sample input, expected output, the script you ran, the
> output it gives, and what's wrong with that output.
>
> Ed.- Hide quoted text -
>
> - Show quoted text -

ed,

it gives me list me twice output of the first columnfor example
dg_te1 is twice i want it in single and want to add the both
values which generated by the dg_te1 here in case its 11+15 .. .so it
become ease of my work....thanks
Nikunj [ Di, 04 Dezember 2007 21:24 ] [ ID #1885035 ]

Re: Arithmatic operation

On 12/4/2007 2:24 PM, Nikunj wrote:
> On Dec 4, 11:33 am, Ed Morton <mor... [at] lsupcaemnt.com> wrote:
>
>>On 12/4/2007 11:27 AM, Nikunj wrote:
<snip>
>>>hello i got the output in following format i got dg name twice for
>>>example dg_te1's having 2 output 11 &39 . i want to make it as one
>>>mean i want it dg_te1 50 mean (11+39) . can i do it ...
>>>your help would be appriciated.
>>
>>>dg_te1_Data 14
>>
>>>dg_te1_Data 0
>>
>>>dg_te1 15
>>
>>>dg_te1 11
>>
>>>dg_te1 39
>>
>>>dg_te1 39
>>
>>>Thanks
>>>niks
>>
>>The output you posted doesn't match the input you posted or the script I gave
>>you and it sounds like your requirements have changed. Start again. Tell us what
>>you want to do, post sample input, expected output, the script you ran, the
>>output it gives, and what's wrong with that output.
>>
>> Ed.- Hide quoted text -
>>
>>- Show quoted text -
>
>
> ed,
>
> it gives me list me twice output of the first columnfor example
> dg_te1 is twice i want it in single and want to add the both
> values which generated by the dg_te1 here in case its 11+15 .. .so it
> become ease of my work....thanks

Here's the input file you posted:

> i have a file called abc.txt , contain of this file is
> # more abc.txt
> 1
> 2
> 34
> 45
> 65
> ......

where all this dg_tel stuff is coming from is a mystery. Seriously - do what I
suggested about starting over.

Ed.
Ed Morton [ Di, 04 Dezember 2007 21:49 ] [ ID #1885039 ]

Re: Arithmatic operation

On 2007-12-04, Nikunj <niku.khakhar [at] gmail.com> wrote:
>
>
>
> it gives me list me twice output of the first columnfor example
> dg_te1 is twice i want it in single and want to add the both
> values which generated by the dg_te1 here in case its 11+15 .. .so it
> become ease of my work....thanks

awk '{sum[$1]+=$2} END{for(x in sum) print x,xum[x]}'
Bill Marcum [ Di, 04 Dezember 2007 21:51 ] [ ID #1885040 ]

Re: Arithmatic operation

On 12/4/2007 2:51 PM, Bill Marcum wrote:
> On 2007-12-04, Nikunj <niku.khakhar [at] gmail.com> wrote:
>
>>
>>
>>it gives me list me twice output of the first columnfor example
>>dg_te1 is twice i want it in single and want to add the both
>>values which generated by the dg_te1 here in case its 11+15 .. .so it
>>become ease of my work....thanks
>
>
> awk '{sum[$1]+=$2} END{for(x in sum) print x,xum[x]}'

That won't do it. In the part you snipped, he said this:

> hello i got the output in following format i got dg name twice for
> example dg_te1's having 2 output 11 &39 . i want to make it as one
> mean i want it dg_te1 50 mean (11+39) . can i do it ...
> your help would be appriciated.
>
>
> dg_te1_Data 14
>
> dg_te1_Data 0
>
> dg_te1 15
>
> dg_te1 11
>
> dg_te1 39
>
> dg_te1 39

so assuming he has an input file with a format similair to that, then your
script would produce a total of 104 for the "dg_tel" records whereas the OP says
it should be 50. There's something he's not telling us....

Ed.
Ed Morton [ Di, 04 Dezember 2007 23:07 ] [ ID #1885043 ]
Linux » comp.unix.shell » Arithmatic operation

Vorheriges Thema: Sar doubt
Nächstes Thema: How to put an entry in crontab using only one command ?