简体   繁体   中英

How can I write a bash or awk script that reads numbers from txt file, and divide each number by a variable?

I have a sample text file as follow color.txt:

68.08602255 1.24295415 84.00087345 255
68.4701724 2.44923165 85.5337626 255

I want to write a bash script that allows me to go into each number and divide them by 255. These numbers are color values between 0-255, some programs require values between 0-1 instead. The values will only be divided by 255. The above text would have the following output

0.267004 0.00487433 0.329415 1
0.26851 0.00960483 0.335427 1
#!/bin/sh

var=255
awk -v var="$var" '{ print $1 / var, $2 / var, $3 / var, $4 / var }'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM