Computing.Net > Forums > Unix > Multiply numerical content in file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Multiply numerical content in file

Reply to Message Icon

Name: Sup
Date: February 4, 2003 at 19:06:28 Pacific
OS: Unix
CPU/Ram: 128
Comment:

Hi...need your expertise...I'm a newbie to scripting. I have a file whose numerical content, I need to multiply by 1000. The file is called crc.sdf

The format of its content is as follow.

(INTERCONNECT U663/Y ERRFLG (0.000082:0.000082:0.000082) (0.000082:0.000082:0.000082))
(INTERCONNECT U667/Y DOUTVALID (0.000054:0.000054:0.000054) (0.000054:0.000054:0.000054))
(INTERCONNECT DOUTREADY U524/A (0.000550:0.000550:0.000550) (0.000550:0.000550:0.000550))

Basically I need to change those numbers, 3 numbers in each parenthesis (they represent time in ns to ps). It's probably easiest to search for . then take the number and multiply it but I'm not sure exactly how to do that. Any help is greatly appreciated.

Sup




Sponsored Link
Ads by Google

Response Number 1
Name: Jerry Lemieux
Date: February 5, 2003 at 07:24:20 Pacific
Reply:

Try this:

#!/bin/ksh

function count {

output1=$(print "$2 * 1000;scale=2" | bc)
output2=$(print "$3 * 1000;scale=2" | bc)
output3=$(print "$4 * 1000;scale=2" | bc)

print "The results are $output1 $output2 $output3"

}

IFS="():
"

exec 3 ./data.comp

while read -u3 line
do
case $line in
*I* ) : #print $line
;;
* ) count $line
;;
esac
done

Please note: There should be a left angle bracket between the exec 3 and the ./data.comp. That is what I named your data file as. Change it as appropriate.

Jerry


0
Reply to Message Icon

Related Posts

See More


how to read binary files ... INformation about NIS



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Multiply numerical content in file

content in files from file.tar www.computing.net/answers/unix/content-in-files-from-filetar/5720.html

flexibility in file naming schemes?? www.computing.net/answers/unix/flexibility-in-file-naming-schemes/570.html

Search file & add string after that www.computing.net/answers/unix/search-file-amp-add-string-after-that/6343.html