#include <iostream> using namespace std; int main() { int a[4]={1,2,3}; cout<<2[a]<<endl; return 0; } [[email protected] 20160731]$ echo "wz" | grep ‘.‘ wz [[email protected] 20160731]$ echo "wz" | grep ‘w‘ wz [[email protected] 20160731]$ echo "wz zx" | grep ‘wz.‘ wz zx [[email protected] 20160731]$ echo "wz zx" | grep ‘.z‘ wz zx [[email protected] 20160731]$ su Password: [[email protected] 20160731]# echo "wz zx" | grep ‘.z‘ wz zx [[email protected] 20160731]# echo "wz zx" | grep ‘.x‘ wz zx [[email protected] 20160731]# echo "wz zx" | grep ‘w[abcz]‘ wz zx [[email protected] 20160731]# echo "wz zx" | grep ‘w[0-9]‘ [[email protected] 20160731]# echo "wz zx" | grep ‘w[^0-9]‘ wz zx [[email protected] 20160731]# echo "wz zx" | grep ‘w[[:digit:]]‘ [[email protected] 20160731]# echo "wz zx" | grep ‘w[[:alpha:]]‘ wz zx [[email protected] 20160731]# echo "wz zx" | grep ‘.?‘ [[email protected] 20160731]# echo "wz zx" | grep ‘.+‘ [[email protected] 20160731]# echo "" | grep ‘.+‘ [[email protected] 20160731]# echo "a" | grep ‘.+‘ [[email protected] 20160731]# echo "a2" | grep ‘.[2-5]+‘ [[email protected] 20160731]# echo "a2" | grep ‘.[2-5]?‘ [[email protected] 20160731]# echo "a2" | grep ‘.{3,}‘ [[email protected] 20160731]# echo "a22" | grep ‘.{3,}‘ [[email protected] 20160731]# echo "a22" | grep ‘.{3}‘ [[email protected] 20160731]# echo "a22123" | grep ‘.{3}‘ [[email protected] 20160731]# [[email protected] 20160731]# echo "a22123" | grep ‘.{,3}‘ [[email protected] 20160731]# [[email protected] 20160731]# echo "aaa" | grep ‘a{1,3}‘ [[email protected] 20160731]# echo "aaa bbb" | grep ‘^b‘ [[email protected] 20160731]# echo "aaa bbb" | grep ‘^a‘ aaa bbb [[email protected] 20160731]# echo "aaa bbb" | grep ‘b$‘ aaa bbb [[email protected] 20160731]# echo "aaa bbb " | grep ‘b$‘ [[email protected] 20160731]# echo "aaa bbb " | grep ‘b\b‘ aaa bbb [[email protected] 20160731]# echo "aaa bbb " | grep ‘b\B‘ aaa bbb [[email protected] 20160731]# echo "aaa bbb " | grep ‘\B‘ aaa bbb [[email protected] 20160731]# echo "aaa bbb " | grep ‘\Ba‘ aaa bbb [[email protected] 20160731]# echo "xxaaaxx bbb " | grep ‘\Ba\B‘ xxaaaxx bbb [[email protected] 20160731]# echo "aaa bbb " | grep ‘\Ba\B‘ aaa bbb [[email protected] 20160731]# echo "ab121212 " | grep ‘12{3}‘ [[email protected] 20160731]# echo "ab121212222 " | grep ‘12{3}‘ [[email protected] 20160731]# echo "ab121212222 " | grep ‘(12){3}‘ [[email protected] 20160731]# echo "ab121212222()" | grep ‘\(\){3}‘ [[email protected] 20160731]# echo "ab121212222()" | grep ‘\(\)$‘ ab121212222() [[email protected] 20160731]# echo "ab121212222()" | grep ‘\(\)$|(12){3}‘ [[email protected] 20160731]# [[email protected] 20160731]# echo "ab121212222()" | grep ‘\(\)$|(12){3}|^a‘ [[email protected] 20160731]# 190 vim file 191 grep ‘[0-9]{2,11}‘ file 192 grep -E --color ‘[0-9]{2,11}‘ file 193 grep -E --color ‘^[0-9]{2,11}$‘ file 194 history 5 匹配电话 1开头 第二位不为1 2 6 全部是数字开头到结尾 [[email protected] 20160731]# grep -E --color ‘^1[345789][0-9]{2,11}$‘ file [[email protected] 20160731]# grep -E [email protected]$‘ file > history 5^C 匹配邮箱 字符数开头 标准符号结尾 [[email protected] 20160731]# grep -E --color ‘^[a-ZA-Z0-9_][email protected]$‘ file [[email protected] 20160731]# grep --color ‘^[a-ZA-Z0-9_][email protected]$‘ file [[email protected] 20160731]# grep --color ‘^[a-ZA-Z0-9_]\[email protected]$‘ file 匹配IP 3段重复 与一段结尾 [[email protected] 20160731]# grep --color ‘([0-9]{1,3}.){3}[0-9]{1,3}‘ file [[email protected] 20160731]# grep --color ‘^([0-9]{1,3}\.){3}[0-9]{1,3}$‘ file [[email protected] 20160731]# grep --color ‘^\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}$‘ file -E 扩展基准匹配 () | {} + ? 特殊含义 字面意思需要转义 正则基准匹配 【字符类 次数限定 位置限定】 6.在9个点上画10条直线,要求每条直线上至少有三个点?(3分钟-20分钟) 3 4 3 4 6 4 3 4 3 高度的复用性 以(0,0)为心 边长 2 的 正方形4角加(-1,0) (1,0) (0,2)(0,-2) 【sed】 从文件中读一行就匹配处理 到缓冲区 (别名 模式空间) [[email protected] 20160731]# sed ‘/^c/s/^/\/\//‘ abc aaa bbb //ccc ddd [[email protected] 20160731]# sed ‘/c$/p‘ abc 查找 性质 aaa bbb ccc ccc ddd [[email protected] 20160731]# cat abc aaa bbb ccc ddd [[email protected]lhost 20160731]# sed -n ‘/c$/p‘ abc ccc [[email protected] 20160731]# sed -n ‘/^.*\/\//d‘ abc 不影响原文件 [[email protected] 20160731]# cat abc aaa bbb //ccc ddd [[email protected] 20160731]# sed -i ‘/^.*\/\//d‘ abc 删除abc文件中注释行 -i选项 [[email protected] 20160731]# cat abc aaa bbb ddd [[email protected] 20160731]# sed -i ‘/ddd/s/ddd/ccc/g‘ abc 将ddd行替换为ccc [[email protected] 20160731]# cat abc aaa bbb ccc [[email protected] 20160731]# 注释 5到 10 行5,10 s/^/\/\// [[email protected] 20160731]# sed ‘/a\+/s/a/~a~/‘ abc //~a~aa //bbb //ccc [[email protected] 20160731]# sed ‘/a\+/s/a/~a~/g‘ abc 加g选项就多次执行 //~a~~a~~a~ //bbb //ccc [[email protected] 20160731]# sed -n ‘3p‘ abc //ccc [[email protected] 20160731]# sed -n ‘1,3p‘ abc 打印第3行与前3行 //aaa //bbb //ccc [[email protected] 20160731]# sed -n ‘/aaa/,/ccc/p‘ abc等价于用标签性打印 //aaa //bbb //ccc [[email protected] 20160731]# sed -n ‘/aaa/,3p‘ abc 可以混用 //aaa //bbb //ccc [[email protected] 20160731]# 以下进行3个例子 eg1 保持空间,工厂对产品或半成品保存的地方 sed 模式空间 保持空间 工厂 流水线 库房 (1.默认情况下 sed不会使用保存空间,仅仅显示地运用某些命令时才会被使用) (2.仅仅保存数据,带来意想不到的效果) Gg H h get hold 大写全是追加 不刷新 n 会刷新 N 会更新一行 [[email protected] 20160731]# cat abc //aaa //bbb //ccc [[email protected] 20160731]# sed ‘G‘ abc 显示行加空行 //aaa //bbb //ccc [[email protected] 20160731]# sed ‘/b$/G‘ abc 指定行 b结尾的行加空行 //aaa //bbb //ccc [[email protected] 20160731]# tac abc 倒序读 //ccc //bbb //aaa [[email protected] 20160731]# sed -ne ‘H;${x;s/\n/ /g;p}‘ abc 行列互换 分号;加多命令 H即hold意思 //aaa //bbb //ccc [[email protected] 20160731]# seq 10 1 2 3 4 5 6 7 8 9 10 [[email protected] 20160731]# sed -e ‘/ddd/H‘ -e ‘$G‘ abc //aaa //bbb //ccc [[email protected] 20160731]# cat abc //aaa //bbb //ccc [[email protected] 20160731]# sed -e ‘/ddd/H‘ -e ‘$G‘ abc 没成功 //aaa //bbb //ccc [[email protected] 20160731]# seq 100 | sed -ne ‘H;${x;s/\n/*/g;s/^*//;p}‘ 1*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18*19*20*21*22*23*24*25*26*27*28*29*30*31*32*33*34*35*36*37*38*39*40*41*42*43*44*45*46*47*48*49*50*51*52*53*54*55*56*57*58*59*60*61*62*63*64*65*66*67*68*69*70*71*72*73*74*75*76*77*78*79*80*81*82*83*84*85*86*87*88*89*90*91*92*93*94*95*96*97*98*99*100 [[email protected] 20160731]# seq 100 | sed -ne ‘H;${x;s/\n/+/g;s/^+//;p}‘ | bc 5050 [[email protected] 20160731]# sed -n ‘n;p‘ abc 奇数行 //bbb [[email protected] 20160731]# sed -n ‘p;n‘ abc 偶数行 从0开始 //aaa //ccc [[email protected] 20160731]# awk ‘{print $2;}‘ abc 11 22 33 [[email protected] 20160731]# awk ‘{print $0;}‘ abc //aaa 11 //bbb 22 //ccc 33 [[email protected] 20160731]#
时间: 2024-11-11 02:33:56