I'm using ksh and I'm trying to shorten a column of figures. For example, I'd like to turn:
3456789.9876 to 89.98
567.4956 to 67.49
4669493932.34564 to 32.34
... so the input figure will vary in length, I'm not worried about rounding, I just want the two figures either side of the dp. I probably know how to do it in awk and cut etc I just wondered if there was a more elegant way using say a number format in something like printf.
So far I haven't found a number format that will exclude figures starting from the extreme left (the millions, 100,000s etc). Anyone?
Thanks, but never used expr before, had a go, but dont really have the syntax, could you give me the whole line?
Did it with awk and cut but it was messy. Cant find a way to awk or cut the two decimal places left of the dp without doing a wc on the string, it only seems to work left to right.
sed 's/.*\(..\...\).*/\1/' # format ##.##
sed 's/.*\(...\...\).*/\1/' # format ###.##
sed 's/.*\(....\...\).*/\1/' # format ####.##
sed 's/.*\(..\....\).*/\1/' # format ##.###