replace file extensions
# change .htm files to .html
for file in *.htm ; do mv $file `echo $file | sed 's/\(.*\.\)htm/\1html/'` ; done
# change .html files to .htm
for file in *.html ; do mv $file `echo $file | sed 's/\(.*\.\)html/\1htm/'` ; done
#change .html files to .shtml
for file in *.html ; do mv $file `echo $file | sed 's/\(.*\.\)html/\1shtml/'` ; done
#change .html files to php
for file in *.html ; do mv $file `echo $file | sed 's/\(.*\.\)html/\1php/'` ; done replace string in text
:%s/str1/str2/gc 整个文档
:1,$s/str1/str2/gc 整个文档
:.,$s/str1/str2/gc 从当前到结尾 #extract a range of lines from a text
sed -n 16224,16482p filename > newfile
sed -n -e 12345p filename > newfile
sed '5!d' filename > newfile # compare substring of a field
awk '{if ( substr($1,0,7)>6435201 && substr($1,0,7)<6521605) print $0}' # find a file
find ./ -name 'my*'
# find & cp
find /PATH/TO/YOUR/FILES -name NAME.EXT -exec cp -rfp {} /DST_DIR \; # add numbers in a bash script
num=$((num1 + num2))
num=$(($num1 + $num2)) # also works
num=$((num1 + 2 + 3)) # ...
num=$[num1+num2] # old, deprecated arithmetic expression syntax # Assign Output of Shell Command To Variable
var=$(command-name-here)
var=$(command-name-here arg1)
var=$(/path/to/command)
var=$(/path/to/command arg1 arg2)
var=`command-name-here`
var=`command-name-here arg1`
var=`/path/to/command`
var=`/path/to/command arg1 arg2` # fg/bg/nohup
find /etc/httpd/ -name "httpd.conf" -print >find.dt 2>&1 & awk '{if ($11=="9002" && $6==0) {revenue+=$3;count++}}END{print revenue;print count}' new_ck_table
awk '{if ($3=="+1") count++;}END{print count;}' file.txt
awk 'FNR==NR{a[$1]=1; next}; {if($1 in a) print $0} ' rank02.dat 0201-all.tmp3 > rank02.tmp3 # output third column to end of each row
cut -d ":" -f 3-
# filter empty lines
grep -e '^$' -v # comment /uncomment
ctrl+v -> x
ctrl+v -> shift+i # esc # sort by one column
sort -k 1 0316.new -o 0316.new # remove leading space
sed -e 's/^[ \t]*//' # mount NFS
mount -t nfs 10.134.12.60:/data/online/public localDir ##--------------- high frequency python command ------------------------ # regex text = "<H1>title</H1>"
re.mathc('<.*>', text) # match <H1>title</H1>
re.match('<.*?>',text) # match <H1> # sum of elements in a list
sum = reduce(lambda x,y: x+y, mylist) # compare all elements in two lists
if all(x==y for x, y in zip(X, Y))
do something # get sorted dictionary by key
sorted(dd.keys())
[(key, dd[key]) for key in sorted(dd.keys())]
print ' '.join([str(key)+':'+str(dd[key]) for key in sorted(dd.keys())]) # get sorted dictionary by value
[key for key in sorted(dd, key=dd.get, reverse=True)]
[(key, dd[key]) for key in sorted(dd, key=dd.get, reverse=True)]
print ' '.join([str(key)+':'+str(dd[key]) for key in sorted(dd, key=dd.get, reverse=True)])
sorted(myDict.items(), key=lambda e: e[1][2]) # value is a list # get key intersection of two dictionaries
intersect = set(dict_A.keys()) & set(dict_B.keys()) # sort a list of tuple
sorted_list = sorted(tuples, key=lambda x:x[0]) # map list onto dictionary
mydict = {x.split(':')[0]:x.split(':')[1] for x in mylist} from os.path import basename
from os.path import splitext
fname = splitext(basename(fullname))[0] # sort list and return index of list
sorted_index = sorted(range(len(list)), key=lambda k: list[k]) # intersection of two lists
b1 = [...]
b2 = [...]
intersection = set(b1).intersection(b2) # string to date / date to string
import datetime
obj_date = datetime.datetime.strptime(str_date, "%Y%m%d%H%M").date()
str_date = obj_date.strftime('%Y%m%d%H%M')
obj_date = obj_date + datetime.timedelta(days=-1)
# date to timestamp
time.mktime(time.strptime('2015-03-15 00:00:00', '%Y-%m-%d %H:%M:%S')) # read first N line of a file
with open("datafile") as myfile:
head = [next(myfile) for x in xrange(N)]
print head
# remove leading whitespace in vim
%s/^\s*//g

部分用到的python代码的更多相关文章

  1. 可爱的豆子——使用Beans思想让Python代码更易维护

    title: 可爱的豆子--使用Beans思想让Python代码更易维护 toc: false comments: true date: 2016-06-19 21:43:33 tags: [Pyth ...

  2. if __name__== "__main__" 的意思(作用)python代码复用

    if __name__== "__main__" 的意思(作用)python代码复用 转自:大步's Blog  http://www.dabu.info/if-__-name__ ...

  3. Python 代码风格

    1 原则 在开始讨论Python社区所采用的具体标准或是由其他人推荐的建议之前,考虑一些总体原则非常重要. 请记住可读性标准的目标是提升可读性.这些规则存在的目的就是为了帮助人读写代码,而不是相反. ...

  4. 一行python代码实现树结构

    树结构是一种抽象数据类型,在计算机科学领域有着非常广泛的应用.一颗树可以简单的表示为根, 左子树, 右子树. 而左子树和右子树又可以有自己的子树.这似乎是一种比较复杂的数据结构,那么真的能像我们在标题 ...

  5. [Dynamic Language] 用Sphinx自动生成python代码注释文档

    用Sphinx自动生成python代码注释文档 pip install -U sphinx 安装好了之后,对Python代码的文档,一般使用sphinx-apidoc来自动生成:查看帮助mac-abe ...

  6. 上传自己的Python代码到PyPI

    一.需要准备的事情 1.当然是自己的Python代码包了: 2.注册PyPI的一个账号. 二.详细介绍 1.代码包的结构: application \application __init__.py m ...

  7. 如何在batch脚本中嵌入python代码

    老板叫我帮他测一个命令在windows下消耗的时间,因为没有装windows那个啥工具包,没有timeit那个命令,于是想自己写一个,原理很简单: REM timeit.bat echo %TIME% ...

  8. ROS系统python代码测试之rostest

    ROS系统中提供了测试框架,可以实现python/c++代码的单元测试,python和C++通过不同的方式实现, 之后的两篇文档分别详细介绍各自的实现步骤,以及测试结果和覆盖率的获取. ROS系统中p ...

  9. 让计算机崩溃的python代码,求共同分析

    在现在的异常机制处理的比较完善的编码系统里面,让计算机完全崩溃无法操作的代码还是不多的.今天就无意运行到这段python代码,运行完,计算机直接崩溃,任务管理器都无法调用,任何键都用不了,只能强行电源 ...

  10. python代码缩进

    习惯了java,c++之类的宽容,初学python,被它摆了道下马威,写if else,竟然必须要我正确用缩进格式,原来在python里不能用括号来表示语句块,也不能用开始/结束标志符来表示,而是靠缩 ...

随机推荐

  1. VBA中练习ADO:ActiveX Data Object

    前期绑定,要先添加引用---"Microsoft ActiveX Data Objects 6.1" ADO学习的权威参考可点击:w3school ADO简单理解:是几个Activ ...

  2. [转] 浅谈Linux系统的启动流程

    原文:http://blog.csdn.net/justdb/article/details/9621271 版权声明:本文为博主原创文章. Linux系统的启动时通过读取不同的配置文件,执行相应的S ...

  3. 将InfoObject作为信息提供者Characteristic is InfoProvider

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  4. 标准DSO设置

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  5. HDU 5775 Bubble Sort(冒泡排序)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  6. FPGA相关术语(一)

    参考资料: 1. 数字时钟管理单元DCM 2. RS-232 知识点: ● Xilinx) Digital Clock Manager(DCM) primitive用于实现延迟锁相环(delay lo ...

  7. centos配置163源

    1.参考Centos镜像帮助 (1.1)备份原始repo shell> sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/Ce ...

  8. 《BI项目笔记》历年感官评吸质量均值变化分析Cube的建立

    分析主题主要维度:烟叶级别.烟叶级别按等级信息.烟叶级别按分级标准(标准维度)产地(父子维度)检测时间(时间维度,以Tqc_Raw_SmokingTest .CheckTime字段派生CheckDat ...

  9. h.APR通道是个怎么回事

    APR通道是Tomcat比较有特色的通道,在早期的JDK的NIO框架不成熟的时候,因为java的网络包的低效,Tomcat使用APR开源项目做网络IO,这样有效的缓解了java语言的不足,提供了一个高 ...

  10. android定义启动唯一apk

    <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="ht ...