Skip to content

Instantly share code, notes, and snippets.

View luistung's full-sized avatar
🎯
Focusing

luistung

🎯
Focusing
View GitHub Profile
@luistung
luistung / sort.py
Last active August 29, 2015 14:01
文件排序
import sys
lines = []
for line in sys.stdin:
line = line.rstrip()
tokens = line.split('\t')
src, tgt = tokens[0], tokens[1]
lines.append(((src,tgt), line)) #TODO
lines.sort(key=lambda a:a[0])
@luistung
luistung / counter
Created May 22, 2014 07:18
python全局计数器
def counter(interval):
if not hasattr(counter,'count'):
counter.count = 0
counter.count += 1
import sys
if counter.count % interval == 0: print >>sys.stderr, counter.count
@luistung
luistung / swap
Created April 28, 2014 13:22
交换两个文件
#!/bin/sh
if [[ $# != 2 && $# != 3 ]]
then
echo '需要至少两个参数' >&2
echo 'usage:'
echo "$(basename $0) file1 file2 tmpdir" >&2
exit 1
fi
@luistung
luistung / split_by_field.py
Last active January 1, 2016 07:19
按第一字段切分文件
#!/bin/env python
#usage argv[0] file_tobe_split target_dir
#按第一字段切分文件
import sys
src_file = sys.argv[1]
tgt_dir = sys.argv[2]