Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a file which contains so many values which ends with a string px. I need to find all those values, multiple them with 0.43 and again write them to the file with the substring 'pt' instead of 'px'
How do I achieve this ??

eg string from the file:

CSS
.ClassOne
{
    margin: .35em 5px;
    overflow: hidden;
    padding: 0 1.4em 0 .5em;
    position: relative;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ClassTwo
{
    border: 7px solid #FFF;
    border-top-color: #000;
    position: absolute;
    right: 6px;
    top: .95em;
}
.ClassThree
{
    bottom: 5px;
    height: 1px;
    left: 1em;
    position: absolute;
    right: 2em;
}


To find all the values that ends with px, and convert them to points by multiplying with 0.43 and write them back to the file.
Example: 5px = 2.15pt, -9px = -3.87pt

How to achieve this using a single line command line in unix?? Since I am new to shell scripting, I need some help. All I know is that it can be achieved using sed -i.
Posted

 
Share this answer
 
You can use sed -e with regular expressions and the global flag. See https://www.google.com/search?q=man+sed[^] for samples.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900