Shell
文章平均质量分 60
假装80后
一个不念过去,不畏将来的程序员
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
awk check text file line-by-line
For example; using awk to check whether a text file has exactly following 3 lines: AA BB CC cat $infile | awk ' BEGIN { retcode = 0; rowcount = 3 } NR==1 { if ( $0 != "AA") { retco原创 2016-10-16 12:34:36 · 337 阅读 · 0 评论 -
sed 提取匹配的字符串内容
# STR="MAIL FROM(CCC) TO(DDD)" #echo $STR | sed -n 's/.*FROM(\([^)]\{1,\}\)).*TO(\(.*\))/\1-\2/g'p 提取括号里面的内如 STR="MAIL FROM(ABCD) BODY" echo $STR | sed 's/^.*FROM(\(.*\)).*$/\1/g' # A原创 2017-03-05 14:38:30 · 29819 阅读 · 3 评论 -
Dispatch tasks among muliple workors
Sometimes we many have many tasks to be executed by several workors. we wish tasks can be executed by workors in equal division Basic solution: 1. put all tasks into a PIPO pipeline. 2. Bring up原创 2016-10-20 22:58:52 · 483 阅读 · 0 评论 -
KSH - String Operaters
#!/bin/kshvar="123451234512345"output=${#var} # 15output=${var#1*4} # 51234512345, start must be the first char of that stringoutput=${var##1*4} # 5, start must be t原创 2009-11-04 12:19:00 · 730 阅读 · 0 评论 -
KSH variable
KSH Variable Category function variable It must be explicitly declared within a function using typeset command.It's valid only within the function it is declared. script/file variable It's原创 2016-10-16 12:04:52 · 593 阅读 · 0 评论 -
variable in while loop between ksh vs. bash
In BASH, a variable is changed in a loop, but is kept untouched when quit loop; i.e, the new value set in loop is lost. function showme { echo -n "Loop=$linecount" sh -c 'echo " PID=$PPID"' }原创 2016-10-20 22:38:23 · 525 阅读 · 0 评论 -
ksh array variable
Define Array Variable set -A COLORS RED BLUE GREEN or COLORS[0]=RED COLORS[1]=BLUE COLORS[2]=GREEN Get Array Size ${#COLORS[@]} Notice: this is the occupi原创 2016-10-16 12:49:51 · 653 阅读 · 0 评论 -
KSH print numeric value 0000-9999
Problem Statement: Print numeric value 0000-9999 # use for loop #!/bin/ksh for i in {0..9999} do s=$(printf "%04d" $i) echo "for $s times" done # use while loop #!/bin/ksh原创 2016-10-20 22:14:16 · 655 阅读 · 0 评论 -
ksh control statement
Case Statement Simple Case case ${FileType} in SHELL) FileType=SHELL ;; C) FileType=CPP ;; JAVE) FileType=JAVA ;; (*) FileType=UNKNOW return 255 esac Pa原创 2016-10-16 12:48:29 · 341 阅读 · 0 评论 -
ksh regular expression pattern
Pattern Element * Matches any string, including the nullstring. ? Matches any single character. [...] Matches any one of the enclosedcharacters. [!...] Any character not原创 2016-10-16 12:45:26 · 381 阅读 · 0 评论 -
KSH comparison operator
String Comparison [[ str1 == pattern ]] str1 = pattern, [[ str1 = pattern ]] Same as == above, but is obsolete [[ str1 != pattern ]] str1 != pattern [[ str1 [[ st原创 2016-10-16 12:42:08 · 380 阅读 · 0 评论 -
Unix Shell - Case statement
#!/bin/kshX=XYZcase $X inX* | *Z) # X in pattern or sample echo "1111111" ;;X*Z) # arg in pattern echo "2222222" ;;*) #default echo "3333333"原创 2009-11-03 15:52:00 · 842 阅读 · 0 评论 -
ksh trap signal
What's Signal When a signal is received, a script can do one of three actions: Ignore it and do nothing.Catch the signal using trap and take appropriate action.Take the default action. All th原创 2016-10-16 12:51:55 · 727 阅读 · 0 评论 -
ksh getopts function
This is a sample on how to use getopts to parse command line options. Principle while getopts "ab:c" opt; do case $opt in a ) process option -a ;; b ) process option -b原创 2016-10-16 12:46:34 · 726 阅读 · 0 评论 -
Build and Install a PERL module
1. Build & Install For example we are going to install Template Perl module under directory ~/tools/perlmodule Download Template-Toolkit-2.24.tar.gzUnzip Template-Toolkit-2.24perl Makefi原创 2016-10-16 12:28:49 · 633 阅读 · 0 评论 -
Unix Shell find/xargs
// Solaris 1. find ./ -name "*.jar" -exec jar -tvf {} /; For each file found from find command, it will invoke a new process space to run tar -tvf .... 2. find ./ -name "*.jar" | xa原创 2010-04-27 11:10:00 · 1130 阅读 · 0 评论 -
Script to merge configuration file
目地:把一个配置文件里面的配置项拷贝到另一个配置文件中。 前提要求:两个配置文件基本相同, 文件名相同, 主要用在软件升级的情况下, 新版本的配置文件和老版本的配置文件基本相同, 但是可能新增或者删除了部分配置项, 现在需要一个工具把老的配置值拷贝到新的配置文件里面去. 原来的/u/XXX/old/a.conf新的/u/XXX/new/a.conf原创 2010-04-21 16:57:00 · 704 阅读 · 0 评论 -
ClearCase - How to pass 'alias' to sub-shell after setview command is executed.
1. Put your alias into your ~/.$(SHELL)rc file, for ksh example#~/>:cat .kshrcalias ll=ls -lalias scp=scp -F ~/.ssh/ssh_config#~/>:cat .kshrc For c shell, it should be .cshrcFor bash原创 2009-12-23 16:23:00 · 1034 阅读 · 0 评论 -
Unix Shell - Digital Algorithm
#!/bin/ksh X=10Y=2 Z=`expr $X + $Y` # orecho $Z(( Z = $X / 4 + 2 )) # orecho $ZZ=$((X+Y))echo $ZZ=$(awk /^PermSize=/ {print substr($0, 10, 30)} $ODBCINI)echo $ZZ=$(echo 100 | gre原创 2009-11-03 16:04:00 · 614 阅读 · 0 评论 -
Unix Shell - If statement
# Notice: this is executed within /bin/ksh ############# format #############if [ $condition ]then ...elif [ ] ...else ...fiif /usr/bin/id | /usr/bin/grep uid=0(原创 2009-11-03 15:35:00 · 1009 阅读 · 0 评论 -
Unix Shell - Command Line Interface
#!/bin/ksh# $#: command line parameters number, exclude the command itself# $0: the command itself# $1: the first command parameter# $2: the second command parameter# $*: all command原创 2009-11-03 14:35:00 · 718 阅读 · 0 评论 -
Unix Shell - Loop statement
#!/bin/ksh######### FOR #################for i in HUP INT QUIT TERMdo echo $idone#cat f.txt#aa ab#ba bb bc##!/bin/kshfor word in `cat f.txt`do echo $worddo原创 2009-11-03 16:54:00 · 889 阅读 · 0 评论
分享