# file contains 5000 lines split -l 1000 tmp.log -d -a 2 tmp_part_ # will result like below tmp_part_00 tmp_part_01 ... tmp_part_04
Merg文件
1
cat part_dir/tmp_part_* >> tmp.log
统计用户存储占用情况(sort)
du -sh ./* | sort -rh find ./data -size +200M | xargs ls -lSh
字符处理
统计字符串单词个数
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# 方法1 echo'one two three four five' | wc -w # 方法2 echo'one two three four five' | awk '{print NF}' # 方法3 s='one two three four five' set${s} echo$# # 方法4 通过数组方式获取 ='one two three four five' a=($s) echo${#a[@]} # 方法5 echo'one two three four five' | tr' ''\n' | wc -l
${string#substring} Deletes shortest match of $substring from front of $string. ${string##substring} Deletes longest match of $substring from front of $string
1 2 3 4 5 6 7 8 9 10 11 12 13 14
stringZ=abcABC123ABCabc # |----| shortest # |----------| longest echo ${stringZ#a*C} # 123ABCabc # Strip out shortest match between 'a' and 'C'.
echo ${stringZ##a*C} # abc # Strip out longest match between 'a' and 'C'.
# You can parameterize the substrings. X='a*C' echo ${stringZ#$X} # 123ABCabc echo ${stringZ##$X} # abc # As above
数值计算与判断
循环是根据奇偶性做出不同处理,switch flag
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# HOW TO FIND A NUMBER IS EVEN OR ODD IN SHELL SCRIPT # WRITTEN BY SURAJ MAITY # TUTORIALSINHAND.COM clear echo "---- EVEN OR ODD IN SHELL SCRIPT -----" echo -n "Enter a number:" read n echo -n "RESULT: " if [ `expr $n % 2` == 0 ] then echo "$n is even" else echo "$n is Odd" fi
2.”%”号的使用
${string%substring} Deletes shortest match of $substring from back of $string. string%%substring} Deletes longest match of $substring from back of $string.
替换每行所有匹配 sed 's/01/Ab/g' test_sed 1234567890 23456789Ab 3456789Ab2 456789Ab23 注意:第一行的0,1没有分别替换为A,b
删除:d命令
1 2 3 4
sed '2d' example #删除example文件的第二行。 sed '2,$d' example #删除example文件的第二行到末尾所有行。 sed '$d' example #删除example文件的最后一行。 sed '/test/'d example #匹配'test'并删除
example——-删除example文件所有包含test的行。
替换:s命令 $ sed 's/test/mytest/g' example——-在整行范围内把test替换为mytest。如果没有g标记,则只有每行第一个匹配的test被替换成mytest。 $ sed -n 's/^test/mytest/p' example——-(-n)选项和p标志一起使用表示只打印那些发生替换的行。也就是说,如果某一行开头的test被替换成mytest,就打印它。 $ sed 's/^192.168.0.1/&localhost/'example——-&符号表示替换换字符串中被找到的部份。所有以192.168.0.1开头的行都会被替换成它自已加localhost,变成192.168.0.1localhost。 $ sed -n 's/\(love\)able/\1rs/p' example——-love被标记为1,所有loveable会被替换成lovers,而且替换的行会被打印出来。 $ sed 's#10#100#g' example——-不论什么字符,紧跟着s命令的都被认为是新的分隔符,所以,“#”在这里是分隔符,代替了默认的“/”分隔符。表示把所有10替换成100。
选定行的范围:逗号 $ sed -n '/test/,/check/p' example——-所有在模板test和check所确定的范围内的行都被打印。 $ sed -n '5,/^test/p' example——-打印从第五行开始到第一个包含以test开始的行之间的所有行。 $ sed '/test/,/check/s/$/sed test/' example——-对于模板test和west之间的行,每行的末尾用字符串sed test替换。
多点编辑:e命令 $ sed -e '1,5d' -e 's/test/check/'example——-(-e)选项允许在同一行里执行多条命令。如例子所示,第一条命令删除1至5行,第二条命令用check替换test。命令的执行顺序对结果有影响。如果两个命令都是替换命令,那么第一个替换命令将影响第二个替换命令的结果。 $ sed --expression='s/test/check/' --expression='/love/d' example——-一个比-e更好的命令是—expression。它能给sed表达式赋值。
从文件读入:r命令 $ sed '/test/r file' example——-file里的内容被读进来,显示在与test匹配的行后面,如果匹配多行,则file的内容将显示在所有匹配行的下面。
写入文件:w命令 $ sed -n '/test/w file' example——-在example中所有包含test的行都被写入file里。
追加命令:a命令 $ sed '/^test/a\\--->this is a example' example<——-‘this is a example’被追加到以test开头的行后面,sed要求命令a后面有一个反斜杠。
插入:i命令 $ sed '/test/i\\ new line -------------------------' example 如果test被匹配,则把反斜杠后面的文本插入到匹配行的前面。 下一个:n命令 $ sed '/test/{ n; s/aa/bb/; }' example——-如果test被匹配,则移动到匹配行的下一行,替换这一行的aa,变为bb,并打印该行,然后继续。
变形:y命令 $ sed '1,10y/abcde/ABCDE/' example——-把1—10行内所有abcde转变为大写,注意,正则表达式元字符不能使用这个命令。
退出:q命令 $ sed '10q' example——-打印完第10行后,退出sed。
保持和获取:h命令和G命令 $ sed -e '/test/h' -e example——-在sed处理文件的时候,每一行都被保存在一个叫模式空间的临时缓冲区中,除非行被删除或者输出被取消,否则所有被处理的行都将打印在屏幕上。接着模式空间被清空,并存入新的一行等待处理。在这个例子里,匹配test的行被找到后,将存入模式空间,h命令将其复制并存入一个称为保持缓存区的特殊缓冲区内。第二条语句的意思是,当到达最后一行后,G命令取出保持缓冲区的行,然后把它放回模式空间中,且追加到现在已经存在于模式空间中的行的末尾。在这个例子中就是追加到最后一行。简单来说,任何包含test的行都被复制并追加到该文件的末尾。
保持和互换:h命令和x命令 $ sed -e '/test/h' -e '/check/x' example ——-互换模式空间和保持缓冲区的内容。也就是把包含test与check的行互换。
set nocompatible " 关闭 vi 兼容模式 syntax on " 自动语法高亮 "colorscheme molokai " 设定配色方案 set number " 显示行号 set noswapfile " 不产生.swap, .swo文件 "set cursorline " 突出显示当前行 set ruler " 打开状态栏标尺 set shiftwidth=4 " 设定 << 和 >> 命令移动时的宽度为 4 set softtabstop=4 " 使得按退格键时可以一次删掉 4 个空格 set tabstop=4 " 设定 tab 长度为 4 set nobackup " 覆盖文件时不备份 "set autochdir " 自动切换当前目录为当前文件所在的目录 filetype plugin indent on " 开启插件 set backupcopy=yes " 设置备份时的行为为覆盖 set ignorecase smartcase " 搜索时忽略大小写,但在有一个或以上大写字母时仍保持对大小写敏感 "set nowrapscan " 禁止在搜索到文件两端时重新搜索 set incsearch " 输入搜索内容时就显示搜索结果 set hlsearch " 搜索时高亮显示被找到的文本 set noerrorbells " 关闭错误信息响铃 set novisualbell " 关闭使用可视响铃代替呼叫 set t_vb= " 置空错误铃声的终端代码 " set showmatch " 插入括号时,短暂地跳转到匹配的对应括号 " set matchtime=2 " 短暂跳转到匹配括号的时间 set magic " 设置魔术 set hidden " 允许在有未保存的修改时切换缓冲区,此时的修改由 vim 负责保存 set guioptions-=T " 隐藏工具栏 set guioptions-=m " 隐藏菜单栏 set smartindent " 开启新行时使用智能自动缩进 set backspace=indent,eol,start " 不设定在插入状态无法用退格键和 Delete 键删除回车符 set cmdheight=1 " 设定命令行的行数为 1 set laststatus=2 " 显示状态栏 (默认值为 1, 无法显示状态栏) set statusline=\ %<%F[%1*%M%*%n%R%H]%=\ %y\ %0(%{&fileformat}\ %{&encoding}\ %c:%l/%L%)\ " 设置在状态行显示的信息 "set foldenable " 开始折叠 "set foldmethod=syntax " 设置语法折叠 "set foldcolumn=0 " 设置折叠区域的宽度 "setlocal foldlevel=0 " 设置折叠层数为 "set foldclose=all " 设置为自动关闭折叠 " nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR> " 用空格键来开关折叠 au BufReadPost * if line("'\"") > 0 | if line("'\"") <= line("$") | exe("norm '\"") | else |exe "norm $"| endif | endif hi CursorLine cterm=NONE ctermbg=lightgray ctermfg=white guibg=lightgray guifg=white hi CursorLine term=bold cterm=bold ctermbg=237 hi CursorColumn cterm=NONE ctermbg=lightgray ctermfg=white guibg=lightgray guifg=white hi CursorColumn term=bold cterm=bold ctermbg=237
" return OS type, eg: windows, or linux, mac, et.st.. function! MySys() if has("win16") || has("win32") || has("win64") || has("win95") return "windows" elseif has("unix") return "linux" endif endfunction
" 用户目录变量$VIMFILES if MySys() == "windows" let $VIMFILES = $VIM.'/vimfiles' elseif MySys() == "linux" let $VIMFILES = $HOME.'/.vim' endif
" 设定doc文档目录 let helptags=$VIMFILES.'/doc'
" 设置字体 以及中文支持 if has("win32") set guifont=Inconsolata:h12:cANSI endif
" 配置多语言环境 if has("multi_byte") " UTF-8 编码 set encoding=utf-8 set termencoding=utf-8 set formatoptions+=mM set fencs=utf-8,gbk
if v:lang =~? '^\(zh\)\|\(ja\)\|\(ko\)' set ambiwidth=double endif
if has("win32") source $VIMRUNTIME/delmenu.vim source $VIMRUNTIME/menu.vim language messages zh_CN.utf-8 endif else echoerr "Sorry, this version of (g)vim was not compiled with +multi_byte" endif
" use Ctrl+[l|n|p|cc] to list|next|previous|jump to count the result " map <C-x>l <ESC>:cl<CR> " map <C-x>n <ESC>:cn<CR> " map <C-x>p <ESC>:cp<CR> " map <C-x>c <ESC>:cc<CR>
" 让 Tohtml 产生有 CSS 语法的 html " syntax/2html.vim,可以用:runtime! syntax/2html.vim let html_use_css=1
"----------------------------------------------------------------- " plugin - taglist.vim 查看函数列表,需要ctags程序 " F4 打开隐藏taglist窗口 "----------------------------------------------------------------- if MySys() == "windows" " 设定windows系统中ctags程序的位置 let Tlist_Ctags_Cmd = '"'.$VIMRUNTIME.'/ctags.exe"' elseif MySys() == "linux" " 设定windows系统中ctags程序的位置 let Tlist_Ctags_Cmd = '/usr/bin/ctags' endif nnoremap <silent><F4> :TlistToggle<CR> let Tlist_Show_One_File = 1 " 不同时显示多个文件的tag,只显示当前文件的 let Tlist_Exit_OnlyWindow = 1 " 如果taglist窗口是最后一个窗口,则退出vim let Tlist_Use_Right_Window = 1 " 在右侧窗口中显示taglist窗口 let Tlist_File_Fold_Auto_Close=1 " 自动折叠当前非编辑文件的方法列表 let Tlist_Auto_Open = 0 let Tlist_Auto_Update = 1 let Tlist_Hightlight_Tag_On_BufEnter = 1 let Tlist_Enable_Fold_Column = 0 let Tlist_Process_File_Always = 1 let Tlist_Display_Prototype = 0 let Tlist_Compact_Format = 1
"----------------------------------------------------------------- " plugin - mark.vim 给各种tags标记不同的颜色,便于观看调式的插件。 " \m mark or unmark the word under (or before) the cursor " \r manually input a regular expression. 用于搜索. " \n clear this mark (i.e. the mark under the cursor), or clear all highlighted marks . " \* 当前MarkWord的下一个 \# 当前MarkWord的上一个 " \/ 所有MarkWords的下一个 \? 所有MarkWords的上一个 "-----------------------------------------------------------------
"----------------------------------------------------------------- " plugin - NERD_tree.vim 以树状方式浏览系统中的文件和目录 " :ERDtree 打开NERD_tree :NERDtreeClose 关闭NERD_tree " o 打开关闭文件或者目录 t 在标签页中打开 " T 在后台标签页中打开 ! 执行此文件 " p 到上层目录 P 到根目录 " K 到第一个节点 J 到最后一个节点 " u 打开上层目录 m 显示文件系统菜单(添加、删除、移动操作) " r 递归刷新当前目录 R 递归刷新当前根目录 "----------------------------------------------------------------- " F3 NERDTree 切换 map <F3> :NERDTreeToggle<CR> imap <F3> <ESC>:NERDTreeToggle<CR>
# 全部替换和添加确认环节 :%s/search_for_this/replace_with_this/ - search whole file and replace :%s/search_for_this/replace_with_this/c - confirm each replace
cursor颜色
1 2 3 4 5 6
set cursorline hi CursorLine cterm=NONE ctermbg=lightgray ctermfg=white guibg=lightgray guifg=white set cursorcolumn hi CursorColumn cterm=NONE ctermbg=lightgray ctermfg=white guibg=lightgray guifg=white # 设置更浅的灰色 hi CursorLine term=bold cterm=bold ctermbg=237
echo "I am job: " $1 "my pid is: " $$ sleep 5 if [ $1 -eq 1 ];then echo "this is job 1, success" else echo "this is job 2, failed" lls # 拼写错误的命令,用来报错 fi
disown [-ar] [-h] [jobspec ...] Without options, each jobspec is removed from the table of active jobs. If the -h option is given, each jobspec is not removed from the table, but is marked so that SIGHUP is not sent to the job if the shell receives a SIGHUP. If no jobspec is present, and neither the -a nor the -r option is supplied, the current job is used. If no jobspec is supplied, the -a option means to remove or mark all jobs; the -r option without a jobspec argument restricts operation to running jobs. The return value is 0 unless a jobspec does not specify a valid job.
[root@pvcent107 ~]# screen -dmS Urumchi [root@pvcent107 ~]# screen -list There is a screen on: 12842.Urumchi (Detached) 1 Socket in /tmp/screens/S-root.
# n 天后的日期 yyyy-mm-dd n_days_later=`date --date "${cur_day} n day" +%Y-%m-%d` # n 天前的日期 n_days_ago=`date --date "${cur_day} n day ago" +%Y-%m-%d` ## 获取时间戳,用以比较大小 today_t=`date -d "${today}" +%s` tomorrow_t=`date -d "${tomorrow}" +%s` ## 循环一段时间 yyyy-mm-dd start_day=2019-09-08 end_day=2019-09-17 dt=${start_day} while [ "${dt}" != "${end_day}" ];do echo "-------------统计日期: ${dt}----------------" predt=$(date -I -d "${dt} - 1 day") dt=$(date -I -d "${dt} + 1 day") done
条件语句(if,while)
1 2 3 4 5 6 7 8 9 10 11 12
## while 条件语句 while [ ${today_t} -le ${tomorrow} ]; do # do sth done ## if 条件语句 if [ ${today_t} -le ${tomorrow_t} ]; then #do sth else #do otherthing fi
#file.txt #hello world #this is a test file # 下面这种for循环结果并不是按行显示,其实未按字符显示,主要原因是`cat xxx`命令的到的结果是"hello{space}world{\n}this{sapce}is…… for line in `cat file.txt` do echo $line done; # 正确应该用如下方式 while read line do echo $line done < file.txt
#driver.find_element_by_css_selector("#subDiv > div.aside > div.jquery-accordion-menu.jdskin > div > ul > li:nth-child(5) > a").click()
driver.get("http://kaoqin.jd.com/")
time.sleep(3)
try: driver.find_element_by_css_selector("body > div > div > div > div.login_pop_inner.login_withpc.eye-protector-processed > form > div.login_form_row.formsubmit > input").click() driver.find_element_by_css_selector("#clockIn").click() except selenium.common.exceptions.NoSuchElementException as e: driver.find_element_by_css_selector("#clockIn").click()