Read each line and divide

Hi,

I'm trying to write a script that reads out a file and takes each numbered line and divides by 256. the freemem file is from my vmstat outout's from a cronjob running. there's a lot of line's so i figured this would be easier but I'm drawing a blank on creating the script to read each line and divide by 256.

Here is the basic's of the script so far:

 
#!/usr/bin/ksh
file="freemem"
while read line
do
        echo "$line"
done <"$file"

This works but I can't figure out what I need to do to get the / 256 to work and output it to another file.

Any help would be greatly appriciated!

Also the freemem file looks like this:

 
script
 
 

17:00:01
 
mem=55296MB
faults
------------
fre
74388
56371
39171
108530
174639
178712
177105
172084
160913
166543
160609
152464
157955
163880
169318
158700
177646
180617
175247
167167

script
 
 

17:15:00
 
mem=55296MB
faults
------------
fre
74702

Really not a big deal but if you know how I can exclude the (mem, faults, script and time) would be really great but not important.

Thank you!

awk '/^[0-9]/&&!/:/{ printf "%.4f\n", $0/256; } ' freemem > output_file
1 Like

Thank you!!!!! saved me big time!