Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a list of pixel values in a file, and need each to be half its current value. The pattern for the value is always 123px where 123 varies drastically.

How can I half each pixel value?
I'm guessing sed will be helpful.

share|improve this question

I would suggest you use awk instead of sed.

If your input file file.dat contains one entry per line this will work:

$ awk '{ print $1/2"px"}' file.dat

If you need more sophisticated math use gawk instead of awk.

share|improve this answer
    
Looking into the awk docs now, but each value has exists on a line with other info and another value, like this (it's CSS): .sprite-v16 { background-position: -462px -2002px; } – tbeseda May 13 '11 at 20:16
    
This is more complicated than your question made it seem. While looking around I came across issociate.de/board/post/461416/Math_in_sed/…, but it needs some adijustments for your case. Since CSS can contain simple calculations you could just replace ps by *0.5px for the time being: sed 's/px/\*0\.5px/g'. – Benjamin Bannier May 14 '11 at 13:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .