随笔分类 - shell
常用shell使用
摘要:$n $1 the first parameter,$2 the second... $# The number of command-line parameters. $0 The name of current program. $? Last command or function's return value. $$ The program's PID. $! Last program's PID. $@ Save all the parameters.
阅读全文
摘要:[root@gdc001 biyelunwen]# cat 178 9050 3423 45[root@gdc001 biyelunwen]# awk '{a[$1]=$2}END{for(i in a){printf i":"a[i]"\t"|"sort -n -k1"}}' 178:90 23:45 50:34
阅读全文
摘要:一个文件按列求和:文件内容 a.txt1 2 34 5 67 8 9求和语句:awk '{for(i=1;i<=NF;i++) sum[i]+=$i} END{for(i in sum) print i" "sum[i]}' a.txt求和结果1 122 153 18统计一个IP使用次数 ip.txt文件如下View Code 1 9226 113.11.198.66 2 3 762 113.12.81.57 4 5 1315 113.196.164.67 6 7 1196 117.79.149.221 8 9 9098 117.79.149.2211
阅读全文
摘要:uniqu 是对文件按照列去重,但是和其他常使用的shell不同 uniqu -f1 不是使用f1 字段进行去重,而是忽略f1例如我想对如下文件start.txt安装第二列去重图书音像:小说:悬疑 01.03.38图书音像:小说:言情 01.03.44.01图书音像:小说:职场 01.03.48图书音像:小说:财经 01.03.49图书音像:文艺:文学 01.05图书音像:文艺:传记 01.38图书音像:文艺:艺术 01.07图书音像:文艺:摄影 9941图书音像:青春:青春文学 01.01图书音像:青春:动漫 ...
阅读全文
摘要:要求输出整形,整形位数为四位,不足四位,使用0补齐seq 100 |awk '{printf("%05d\n",$0)}'输出00001000020000300004000050000600007000080000900010000110001200013
阅读全文
摘要:Linux 下打包除了某一个文件下的子文件夹打包命令tar --exclude ProducSpider/data -czvf Sample.tar ProducSpider/使用exclude命令 注意 exclude后面的文件夹名称不能使用/否则无效把打包文件远程拷贝另一台主机scp Sample.tar root@192.168.1.200:/home/root解压文件:tar -zxvf Sample.tar修改终端位置/etc/profile添加:export PS1='[\u@\h:\w] \$'立即生效:source/etc/profile修改后效果:[ab@CC
阅读全文
摘要:shell编程中,经常需要将由特定分割符分割的字符串分割成数组,多数情况下我们首先会想到使用awk 但是实际上用shell自带的分割数组功能会更方便。假如 a=”one,two,three,four”要将$a分割开,可以这样: OLD_IFS=”$IFS” IFS=”,” arr=($a) IFS=”$OLD_IFS” for s in ${arr[@]} do echo “$s” done上述代码会输出 one two three fourarr=($a)用于将字符串$a分割到数组$arr ${arr[0]} ${arr[1]} … 分别存储分割后的数组第1 2 … 项 ,${arr[@]}
阅读全文


浙公网安备 33010602011771号