用于查找,转换和替换文件中的值的Unix脚本 [英] Unix script to find, convert and replace a value from a file

查看:76
本文介绍了用于查找,转换和替换文件中的值的Unix脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件,其中包含许多以字符串px结尾的值。我需要找到所有这些值,用0.43多个它们再次将它们写入带有子串'pt'的文件而不是'px'

如何实现这个?



例如文件中的字符串:



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:

.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;
}





查找所有以px结尾的值,并通过乘以0.43将它们转换为点并将它们写回文件。

示例:5px = 2.15pt,-9px = -3.87pt



如何在unix中使用单行命令行实现这一目标?由于我是shell脚本的新手,我需要一些帮助。我所知道的是它可以使用sed -i实现。



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.

推荐答案

看看 http://stackoverflow.com/questions/2335762/sed-calculations [ ^ ]。

干杯

Andi
Have a look at http://stackoverflow.com/questions/2335762/sed-calculations[^].
Cheers
Andi


你可以用 sed -e 包含正则表达式和全局标志。请参见 https://www.google.com/search?q=man+sed [ ^ ]样本。
You can use sed -e with regular expressions and the global flag. See https://www.google.com/search?q=man+sed[^] for samples.


这篇关于用于查找,转换和替换文件中的值的Unix脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆