awk:
gsub替换
netstat-tnpl|gawk‘$NF~/\/mongod$/{gsub(/.+:/,"",$4);print$4}‘|sort-n
把$4已:结尾的全部替换为空
shell数组
${#ports[@]}#得出数组长度
${ports[@]}=${ports[*]}得出数组值
${ports[@]:8}得出数组后8个
${ports[@]::8}=${ports[@]:0:8}得出数组前8个
$..
分类:
系统相关 时间:
2015-01-14 18:14:45
阅读次数:
264
Syntax:
#sed -e 'command' -e 'command' filename
Note: -e option is optional for sed with single command. sed will execute the each set of command while processing input from the pattern buffer.
...
分类:
其他好文 时间:
2015-01-14 15:35:56
阅读次数:
164
“p” command prints the buffer (remember to use -n option with “p”)
“d” command is just opposite, its for deletion. ‘d’ will delete the pattern space buffer and immediately starts the next cycle.
...
分类:
其他好文 时间:
2015-01-14 15:34:14
阅读次数:
157
cat mem.sh#!/bin/bashIP=`ifconfig | grep 'inet ' | grep -v '127.0.0.1' | awk -F ' ' '{print $2}'| awk -F':' '{print $2}'| head -n 1` //获取IPMAX_mem=95M...
分类:
系统相关 时间:
2015-01-13 22:50:58
阅读次数:
201
今天,Mayuyu来讲一些Linux中常用的命令。
1. grep命令
grep用于过滤自己需要的内容,语法如下
grep Mayuyu --color
过滤出所有包含Mayuyu的行。
2. sed命令
使用普通的vim编辑器在编辑文件时有两个主要的问题
(1)当文件比较大的时候,需要打开文件,占用较大...
分类:
系统相关 时间:
2015-01-13 21:39:59
阅读次数:
427
#cat111.sh#!/bin/bashfunctionrand(){min=$1max=$(($2-$min+1))num=$(cat/dev/urandom|head-n10|cksum|awk-F‘‘‘{print$1}‘)echo$(($num%$max+$min))}rnd=$(rand133)echo$rndexit0#cat222.sh#!/bin/bashfunctionrand(){min=$1max=$(($2-$min+1))num=$(cat/dev/urandom|head-n10..
分类:
其他好文 时间:
2015-01-13 20:03:12
阅读次数:
167
基本组成部分:正则表达式的基本组成部分。正则表达式描述示例\转义符,将特殊字符进行转义,忽略其特殊意义a\.b匹配a.b,但不能匹配ajb,.被转义为特殊意义^匹配行首,awk中,^则是匹配字符串的开始^tux匹配以tux开头的行$匹配行尾,awk中,$则是匹配字符串的结尾tux$匹配以tu..
分类:
系统相关 时间:
2015-01-13 01:34:00
阅读次数:
214
awk提供了许多强大的字符串函数,见下表:awk内置字符串函数gsub(r,s) 在整个$0中用s替代rgsub(r,s,t) 在整个t中用s替代rindex(s,t) 返回s中字符串t的第一位置length(s) 返回s长度match(s,r) 测试s是否包含匹配r的字符串split(s,a,fs...
分类:
其他好文 时间:
2015-01-12 20:58:19
阅读次数:
148
Grep的常用命令语法1. 双引号引用和单引号引用在g r e p命令中输入字符串参数时,最好将其用双引号括起来。例如:“m y s t r i n g”。这样做有两个原因,一是以防被误解为 s h e l l命令,二是可以用来查找多个单词组成的字符串,例如:“jet plane”,如果不用双引号将...
分类:
其他好文 时间:
2015-01-12 20:58:06
阅读次数:
172
1.一两句话描述一下cut命令吧!正如其名,cut的工作就是“剪”,具体的说就是在文件中负责剪切数据用的。cut是以每一行为一个处理对象的,这种机制和sed是一样的。(关于sed的入门文章将在近期发布)2 . cut一般以什么为依据呢?也就是说,我怎么告诉cut我想定位到的剪切内容呢?cut命令主要...
分类:
其他好文 时间:
2015-01-12 20:56:51
阅读次数:
281