2016年3月15日星期二

利用Linux的sed命令可以替换文件里的内容

利用Linux的sed命令可以替换文件里的内容
利用Linux的sed命令可以替换文件里的内容。
用法如下:
sed -i ‘s/[匹配字符串]/[替换字符串]/g’ [文件名]
例如:将文件夹内的所有txt文件里的所有 “Test String”替换成“New Test String”
sed -i ‘s/Test String/New Test String/g’ *.txt
注意:
1.空格不需要用escape
2.点符号需要escape: \.
3.在Mac系统的命令行下使用时,需要为原文件设定一个备份文件。
sed -i ‘.bak’ ‘s/Test String/New Test String/g’ *.txt
如果不想设置备份文件时,在第一个单引号里什么都不输入:
sed -i ” ‘s/Test String/New Test String/g’ *.txt

2016年3月6日星期日

ezdxf 中使用中文

如果在ezdxf中使用中文,建议:
1、dxf版本使用cad2007
2、dxf编码 encoding = 'UTF-8'

import ezdxf

dwg = ezdxf.new('AC1021')
dwg.encoding = 'UTF-8'


3、Default measurement units

4、AutoCAD 中,如何将图形单位从英制转换为公制

5、https://ezdxf.mozman.at/docs/howto.html

6、比0.9更高版本的ezdxf生成的dxf文件,不能被autocad2007打开,能被高版本的cad打开。
    conda install -c conda-forge ezdxf=0.9

2016年3月5日星期六

使用iconv批量转换文本文件编码

$ mkdir utf8
$ find . -name '*.html' | xargs -i  iconv -f cp936 -t utf8 {} -o utf8/{}
$ perl -nle 'if (/<!--bodybegin-->/ .. m(<!--bodyend-->)){print}'  13957672.html
$ find . -name '*.html' | xargs -i  sed -i  's/<font color=E6E6DD> www\.6park\.com<\/font>//g' {}

下面的命令不成功
$ find  . -name  '*.html'  -exec  iconv  -f  cp936  -t  utf8 {} -o utf_{}  \;

for i in *.html; do iconv -f "GBK" -t "UTF-8" -o "utf8"$i $i; done

mac osx 系统自带的iconv没有-o选项


https://askubuntu.com/questions/303222/apply-iconv-to-all-of-the-files-in-a-directory

Batch convert latin-1 files to utf-8 using iconv

make iconv replace the input file with the converted output

2016年1月17日星期日

使用ghostscript 将pdf转换为jpg文件

gswin64.exe  -dNOPAUSE -dBATCH -sDEVICE=jpeg -r400 -dFirstPage=3 -dLastPage=4 -sOutputFile="Pic-%d.jpg" dys.pdf

参数说明见 http://www.ghostscript.com/doc/9.18/Devices.htm


2015年11月15日星期日

Python defaultdict

>>> s = [('yellow', 1), ('blue', 2), ('yellow', 3), ('blue', 4), ('red', 1)]  
>>> d = defaultdict(list)  
>>> for k, v in s:
...             d[k].append(v)
...  
>>> list(d.items())
 [('blue', [2, 4]), ('red', [1]), ('yellow', [1, 3])]

2015年11月12日星期四

重新配置debian系统的locales

sudo dpkg-reconfigure locales