floating-point operations with bash

后端 未结 3 1918
无人共我
无人共我 2021-02-09 05:24

how can I transform the string \"620/100\" into \"6.2\" in a bash script

The context of my question is about image processing. EXIF data are coding the focal length in f

3条回答
  •  故里飘歌
    2021-02-09 06:07

    Thank-you for the answers. bc was what I needed.

    I dont know if posting the result is of any use. Anyway, this the final piece of code for exteracting the focal length of a photo and print it in decimal format. It is supposed to work for all cameras. Tested on 4 cameras of 3 different brands.

    F="your_image.JPG"
    EXIF=$(exiv2 -p v "$F")
    FocalFractional=$( echo "$EXIF" | grep -E '[^ ]*  *Photo *FocalLength '| grep -iohE "[^ ]* *$" )
    Formula="scale=2; "$FocalFractional
    FocalDecimal=$( bc -l <<< "$Formula" )
    echo $ FocalDecimal
    

提交回复
热议问题