Sponsored Content
Full Discussion: Math
Top Forums UNIX for Dummies Questions & Answers Math Post 302943220 by cjcox on Wednesday 6th of May 2015 11:11:57 AM
Old 05-06-2015
Quote:
Originally Posted by cjcox
all the choices you mention will work.

Code:
awk '
{
  val=$0 + 0
  sum=sum+val
}
END {
  l=length(sum)
  if (l > 2) 
    printf("$%s.%s\n",substr(sum,1,(l-2)),substr(sum,(l-1)))
  else
    printf("$0.%s\n",sum)
}' <my_file.txt

Change printf after the else to use %02d instead of %s.
 

10 More Discussions You Might Find Interesting

1. Programming

math.h not working? o.0

Alright, umm i cant get this to work. im looking at some example and a book i have. when i try to compile my program i get an error message. ld: 0711-317 ERROR: Undefined symbol: .sqrt ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information. I did #include<math.h> after my... (2 Replies)
Discussion started by: primal
2 Replies

2. Programming

something about <math.h>

Hi, I got an easy problem for you but really difficult for me 'cause I am pretty new to this field I got header file <math.h> included in my .c file , then I write the code as below: k = sqrt(i); /* both variables k and i are int */ then I cc temp.c it says like this undefined... (4 Replies)
Discussion started by: blf0
4 Replies

3. Programming

some math problems in C

I want to calculate secant method using C language That is a program----> #include<stdio.h> #include<math.h> #include<stdlib.h> main() { double fx(double x); double x0,x1,x2,f0,f1,f2,err; int n,i; printf("\n\n f(x) =x*x*x-5*x-7"); printf("\n\nEnter an interval in" ... (4 Replies)
Discussion started by: cdfd123
4 Replies

4. Programming

math.h in makefile

Hey all, How do I link the math library in a gnu make makefile? I have tried using -lm with the CFLAGS varibale - flags like -Wall and -ggdb work, but -lm does not. I am running gcc - 4.1.2 on a linux machine. (2 Replies)
Discussion started by: kermit
2 Replies

5. UNIX for Dummies Questions & Answers

math in unix

I have 2 variables a=2 b=1 i want to add a and b how do i do this in unix using just the echo command and by assigning it to a different variable like c? (13 Replies)
Discussion started by: khestoi
13 Replies

6. Shell Programming and Scripting

math help

$ x=1 $ y=1.5 $ z=$((x*y)) bash: 1.5: syntax error: invalid arithmetic operator (error token is ".5") What's wrong? (2 Replies)
Discussion started by: rockbike
2 Replies

7. Shell Programming and Scripting

Need help with AWK math

I am trying to do some math, so that I can compare the average of six numbers to a variable. Here is what it looks like (note that when I divide really big numbers, it isn't a real number): $ tail -n 6 named.stats | awk -F\, '{print$1}' 1141804 1140566 1139429 1134210 1084682 895045... (3 Replies)
Discussion started by: brianjb
3 Replies

8. Shell Programming and Scripting

Math Tool

Hi all, I am new to PERL scripts, and i have made my first script which i am posting here. This math tool performs all basic arithmatic functions. #!/usr/bin/perl print "\t----------Welcome to Maths Tool-----------\n"; do { print "Enter your choice :"; print... (2 Replies)
Discussion started by: PranavEcstasy
2 Replies

9. Programming

Math function with C

I have int miles, yards; float kilometers; float kilometers2; miles = 26; yards = 385; kilometers = 1.609 * (miles + yards / 1760.0); where int/float remains a float. How ever if I change it to kilometers = 1.609 * (miles + yards / 1760); ... (7 Replies)
Discussion started by: Fingerz
7 Replies

10. UNIX for Dummies Questions & Answers

Linux Math Help

I am struggling with scripting this challenge a friend and I have. You have file1 and its contents is a single number you have file 2 and its contents are a different number you want to add file1 to file2 and have the output be put into file3 (3 Replies)
Discussion started by: minkyboodle
3 Replies
ppmtosixel(1)						      General Commands Manual						     ppmtosixel(1)

NAME
ppmtosixel - convert a portable pixmap into DEC sixel format SYNOPSIS
ppmtosixel [-raw] [-margin] [ppmfile] DESCRIPTION
Reads a portable pixmap as input. Produces sixel commands (SIX) as output. The output is formatted for color printing, e.g. for a DEC LJ250 color inkjet printer. If RGB values from the PPM file do not have maxval=100, the RGB values are rescaled. A printer control header and a color assignment table begin the SIX file. Image data is written in a compressed format by default. A printer control footer ends the image file. OPTIONS
-raw If specified, each pixel will be explicitly described in the image file. If -raw is not specified, output will default to com- pressed format in which identical adjacent pixels are replaced by "repeat pixel" commands. A raw file is often an order of magni- tude larger than a compressed file and prints much slower. -margin If -margin is not specified, the image will be start at the left margin (of the window, paper, or whatever). If -margin is speci- fied, a 1.5 inch left margin will offset the image. PRINTING
Generally, sixel files must reach the printer unfiltered. Use the lpr -x option or cat filename > /dev/tty0?. BUGS
Upon rescaling, truncation of the least significant bits of RGB values may result in poor color conversion. If the original PPM maxval was greater than 100, rescaling also reduces the image depth. While the actual RGB values from the ppm file are more or less retained, the color palette of the LJ250 may not match the colors on your screen. This seems to be a printer limitation. SEE ALSO
ppm(5) AUTHOR
Copyright (C) 1991 by Rick Vinci. 26 April 1991 ppmtosixel(1)
All times are GMT -4. The time now is 06:20 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy