需求中的数据是这样的:
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
-
<html xmlns="">
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
-
<title>无标题文档</title>
-
<style type="text/css">
-
-
</style></head>
-
-
<body >
-
<div style='position:absolute;left:57px;top:57px;width: 133px;'>上地XXX</div>
-
<div style='position:absolute;left:212.8px;top:60.6px;width: 26.6px;'>2011</div>
-
<div style='position:absolute;left:269.8px;top:60.6px;width: 15.2px;'>10</div>
-
<div style='position:absolute;left:334.4px;top:60.6px;width: 15.2px;'>27</div>
-
<div style='position:absolute;left:380px;top:60.6px;width: 15.2px;'>15</div>
-
<div style='position:absolute;left:57px;top:93.8px;width: 133px;'>XXX</div>
-
<div style='position:absolute;left:226.8px;top:93.8px;width: 133px;'>XXX</div>
-
<div style='position:absolute;left:57px;top:136.8px;width: 133px;'>北京市</div>
-
<div style='position:absolute;left:212.8px;top:136.8px;width: 133px;'>中华人民共和国</div>
-
<div style='position:absolute;left:57px;top:171px;width: 266px;'>北京市XXX有限公司</div>
-
<div style='position:absolute;left:57px;top:209px;width: 266px;'>北京市海淀区上地三街金隅嘉华室</div>
-
<div style='position:absolute;left:57px;top:243.2px;width: 266px;'>地址如果需要写到第二行,就是这里</div>
-
<div style='position:absolute;left:57px;top:275.2px;width: 133px;'>100085</div>
-
<div style='position:absolute;left:226.8px;top:275.2px;width: 133px;'>01234567890用户编码</div>
-
<div style='position:absolute;left:153.4px;top:294px;'>√</div>
-
<div style='position:absolute;left:380px;top:294px;'>√</div>
-
<div style='position:absolute;left:120.2px;top:324.4px;'>√</div>
-
<div style='position:absolute;left:184.8px;top:324.4px;'>√</div>
-
<div style='position:absolute;left:76px;top:380px; width: 114px;'>上衣</div>
-
<div style='position:absolute;left:230.4px;top:380px; width: 19px;'>1</div>
-
<div style='position:absolute;left:268.4px;top:380px; width: 19px;'>2</div>
-
<div style='position:absolute;left:314px;top:380px; width: 38px;'>90$</div>
-
<div style='position:absolute;left:374.8px;top:380px; width: 38px;'>china</div>
-
<div style='position:absolute;left:475px;top:57px; width: 266px;'>收件人</div>
-
<div style='position:absolute;left:444.6px;top:88.8px;width: 133px;'>北京市</div>
-
<div style='position:absolute;left:627px;top:88.8px;width: 133px;'>中华人民共和国</div>
-
<div style='position:absolute; left:444.6px; top:126.8px; width: 266px;'>北京市XX有限公司</div>
-
<div style='position:absolute; left:444.6px; top:161px; width: 266px;'>北京市海淀区上地三街金隅嘉华大厦</div>
-
<div style='position:absolute; left:444.6px; top:199px; width: 266px;'>地址如果需要写到第二行,就是这里</div>
-
<div style='position:absolute; left:444.6px; top:243.2px; width: 133px;'>100085</div>
-
<div style='position:absolute; left:627px; top:243.2px; width: 133px;'>XXX</div>
-
<div style='position:absolute; left:447px; top:274.2px; width: 22.8px;'>100</div>
-
<div style='position:absolute; left:504px; top:274.2px; width: 19px;'>50</div>
-
<div style='position:absolute; left:553.4px; top:274.2px; width: 19px;'>30</div>
-
<div style='position:absolute; left:587.6px; top:274.2px; width: 22.8px;'>150000</div>
-
<div style='position:absolute; left:694px; top:270.4px; width: 76px;'>2.15</div>
-
<div style='position:absolute; left:444.6px; top:311.6px; width: 76px;'>30$</div>
-
<div style='position:absolute; left:570px; top:311.6px; width: 76px;'>0$</div>
-
<div style='position:absolute; left:684px; top:311.6px; width: 76px;'>30$</div>
-
-
<div style='position:absolute;left:76px;top:398px; width: 114px;'>上衣1</div>
-
<div style='position:absolute;left:230.4px;top:398px; width: 19px;'>1.1</div>
-
<div style='position:absolute;left:268.4px;top:398px; width: 19px;'>2.1</div>
-
<div style='position:absolute;left:314px;top:398px; width: 38px;'>90.1$</div>
-
<div style='position:absolute;left:374.8px;top:398px; width: 38px;'>china.1</div>
-
-
<div style='position:absolute;left:76px;top:416px; width: 114px;'>上衣2</div>
-
<div style='position:absolute;left:230.4px;top:416px; width: 19px;'>1.2</div>
-
<div style='position:absolute;left:268.4px;top:416px; width: 19px;'>2.2</div>
-
<div style='position:absolute;left:314px;top:416px; width: 38px;'>90.2$</div>
-
<div style='position:absolute;left:374.8px;top:416px; width: 38px;'>china.2</div>
-
-
<div style='position:absolute;left:76px;top:434px; width: 114px;'>上衣3</div>
-
<div style='position:absolute;left:230.4px;top:434px; width: 19px;'>1.3</div>
-
<div style='position:absolute;left:268.4px;top:434px; width: 19px;'>2.3</div>
-
<div style='position:absolute;left:314px;top:434px; width: 38px;'>90.3$</div>
-
<div style='position:absolute;left:374.8px;top:434px; width: 38px;'>china.3</div>
-
-
<div style='position:absolute;left:76px;top:452px; width: 114px;'>上衣.4</div>
-
<div style='position:absolute;left:230.4px;top:452px; width: 19px;'>1.4</div>
-
<div style='position:absolute;left:268.4px;top:452px; width: 19px;'>2.4</div>
-
<div style='position:absolute;left:314px;top:452px; width: 38px;'>90.4$</div>
-
<div style='position:absolute;left:374.8px;top:452px; width: 38px;'>china.4</div>
-
</body>
-
</html>
当时制作这个html页面用来打印ems的快递单。但是发现对不齐。正好需要将这些坐标数字做-38处理
也就是left和top后面的数字width不要改变
经过群里面大家给的意见最后使用perl完成了这一需求
perl -ne '/left:(\d+\.?\d+)px\;\s*top:(\d+\.?\d+)px\;/;$d=$1-38;$d1=$2-38;s/left:(\d+\.?\d+)px;/left:"$d"px\;/;s/top:(\d+\.?\d+)px;/top:"$d1"px\;/;print'
然而awk就没有那么理想了
awk 'BEGIN{FS=";";OFS=";"}{for(i=1;i<=NF;i++){if($i~/^left/ || $i~/^top/){a=match($i,/[0-9]+\.?[0-9]?/);b=RLENGTH;$i=substr($i,1,a-1)""substr($i,a,b)-38"px"}};NF+=1;print $0}'
得出来的结果在所有行后面多加了一个; 我研究半天也没有找到好办法解决。
如果看到这边博文的您有办法解决,请回复。非常感谢
阅读(1752) | 评论(0) | 转发(0) |