09 2016 档案

shell脚本,awk如何处理文件中上下关联的两行。
摘要:文件d.txt如下内容 ggg 1portals: 192.168.5.41:3260werew 2portals: 192.168.5.43:3260 如何把文件d.txt内容变为如下内容 ggg 192.168.5.41:3260werew 192.168.5.43:3260 解题思路: [ro 阅读全文

posted @ 2016-09-28 01:26 王月波 阅读(5621) 评论(0) 推荐(1) 编辑

shell脚本,awk 匹配的做修改后打印,不匹配的打印。
摘要:文件file内容如下a 1a 2b 3b 4 b 5c 6c 7 要求:第一列匹配b时,如果第二列大于3,那么将第二列加上1后打印,其余的原封不动打印。结果如下: a 1a 2b 3b 5 b 6c 6c 7 阅读全文

posted @ 2016-09-27 20:52 王月波 阅读(1794) 评论(0) 推荐(0) 编辑

shell脚本,awk合并一列的问题。
摘要:文件 file2内容如下:0 qwert1 asdfghjk2 asdjkl2 zxcvbn3 dfghjkll4 222224 tyuiop4 bnm 让第一列相等的合并成一行,不要第一列,也就是变为如下格式:22222;tyuiop;bnmqwertasdfghjkasdjkl;zxcvbndf 阅读全文

posted @ 2016-09-27 00:12 王月波 阅读(5929) 评论(0) 推荐(0) 编辑

shell脚本,awk实现文件a的每行数据与文件b的相对应的行的值相减,得到其绝对值。
摘要:解题思路 文件 shu 是下面这样的。220 34 50 70553 556 32 211 1 14 98 33 文件 jian是下面这样的。1082 想要得到结果是下面这样的。210 24 40 60545 548 24 131 1 12 96 31 用awk来得到想要的结果 [root@loca 阅读全文

posted @ 2016-09-26 00:11 王月波 阅读(3001) 评论(0) 推荐(0) 编辑

shell脚本,awk 根据文件某列去重并且统计该列频次。
摘要:解题方法如下: 解题思路 [root@localhost study]# awk 'NR==FNR{a[$2]++}NR!=FNR&&++b[$2]==1{print $1,$2,a[$2]}' a a1 a 34 s 26 d 1 NR=FNR处理第一个文件a > {a[$2]++} a[$2]+ 阅读全文

posted @ 2016-09-25 00:23 王月波 阅读(9900) 评论(0) 推荐(0) 编辑

shell脚本,awk实现行列转换
摘要:[root@localhost study]# cat file 张三 语文 81 张三 数学 81 李四 语文 76 李四 数学 90 王五 语文 81 王五 数学 100 王五 英语 90 怎么实现为下面的排序??? 81 81 76 90 81 100 90 语文 数学 语文 数学 语文 数学 ... 阅读全文

posted @ 2016-09-25 00:10 王月波 阅读(8799) 评论(0) 推荐(0) 编辑

shell脚本,计算学生分数的题目。
摘要:1.计算学生平均分数的值是多少? 2.计算每门课都大于80分的学生姓名。3.计算每门课都小于90分的学生姓名。 阅读全文

posted @ 2016-09-22 00:21 王月波 阅读(1844) 评论(0) 推荐(0) 编辑

shell脚本,如何用shell打印金字塔
摘要: 阅读全文

posted @ 2016-09-18 01:21 王月波 阅读(3609) 评论(0) 推荐(0) 编辑

shell脚本,通过传入的参数来计算最大值和最小值以及平均值。
摘要:[root@localhost zuoye]# cat quansges.sh #!/bin/bash > file [ ! $# -ge 3 ] && echo "please input three number or more number!" && exit 2 || echo $* >file for i in $* do expr $i + 1 &> /dev/... 阅读全文

posted @ 2016-09-15 23:14 王月波 阅读(4735) 评论(0) 推荐(0) 编辑

shell脚本,如何监控mysql数据库。
摘要:[root@localhost wyb]# cat jkmysql #!/bin/bash status=`/etc/init.d/mysqld status|grep running|wc -l` process=`ps -ef |grep mysqld|grep -v grep|wc -l` port=`lsof -i:3306|grep -i listen|wc -l` mysql... 阅读全文

posted @ 2016-09-14 00:22 王月波 阅读(2718) 评论(0) 推荐(0) 编辑

shell脚本,如何破解字符串对应的md5sum前的RANDOM对应数字?
摘要:已知下面的字符串是通过RANDOM随机数变量md5sum|cut-c 1-8截取后的结果,请破解这些字符串对应的md5sum前的RANDOM对应数字?[root@localhost md5]# cat zifuchuang 21029299 00205d1c a3da1677 1f6d12dd 890684b [root@localhost md5]# cat shuzi.sh #!/bin... 阅读全文

posted @ 2016-09-14 00:06 王月波 阅读(2153) 评论(0) 推荐(0) 编辑

shell脚本,如何监控目录下的文件内容是否被修改。
摘要:第一种方法是通过cmp来进行比对[root@localhost bo]# ls 1.html 2.html 3.html 4.html 5.html 6.html 7.html 8.html 9.html cat.sh [root@localhost bo]# cat cat.sh #!/bin/bash [ ! -f /root/wyb/bo/cat.log ] &&... 阅读全文

posted @ 2016-09-13 00:15 王月波 阅读(6355) 评论(0) 推荐(0) 编辑

shell脚本,一个经典题目。
摘要:[root@localhost wyb]# cat zhuijiu.sh #!/bin/bash #1、写一个脚本执行后,输入名字,产生随机数01-99之间的数字。 #2、如果相同的名字重复输入,抓到的数字还是第一次抓取的结果, #3、前面已经抓到的数字,下次不能在出现相同数字。 #4、第一个输入名字后,屏幕输出信息,并将名字和数字记录到文件里,程序不能退出,继续等待别的学生输入 file... 阅读全文

posted @ 2016-09-10 01:00 王月波 阅读(1301) 评论(0) 推荐(0) 编辑

shelll脚本,根据软链接,找到真实路径
摘要:[root@localhost tmp]# ls -l total 60520 lrwxrwxrwx 1 root root 11 Sep 9 22:54 abc -> /etc/passwd lrwxrwxrwx 1 root root 8 Sep 9 23:02 cde -> /tmp/abc lrwxrwxrwx 1 root root 8 S... 阅读全文

posted @ 2016-09-10 00:19 王月波 阅读(6724) 评论(0) 推荐(0) 编辑

shell脚本,awk实现每个数字加1.
摘要:[root@localhost add]# cat file 1 3 4 5 7 8 9 [root@localhost add]# cat file|awk '{for(i=1;i<=NF;i++){$i+=1}}1' 2 4 5 6 8 9 10 [root@localhost add]# cat file|awk '{for(i=1;i<=NF;i++){$i+=1}}1{print $... 阅读全文

posted @ 2016-09-07 23:47 王月波 阅读(5508) 评论(0) 推荐(0) 编辑

shell脚本,对MySQL数据库进行分库加分表备份
摘要:[root@localhost wyb]# cat table_backup.sh #!/bin/bash flag=0 user=root pass=test mysql -u$user -p"$pass" -e "show databases;" &>/dev/null [ $? -ne 0 ] && read -p "Mysql do not running,start it?(`... 阅读全文

posted @ 2016-09-07 01:18 王月波 阅读(1486) 评论(0) 推荐(0) 编辑

shell脚本,批量创建10个系统帐号并设置密码为随机8位字符串。
摘要:[root@localhost wyb]# cat user10.sh #!/bin/bash #批量创建10个系统帐号wangyb01-wangyb10并设置密码(密码为随机8位字符串)。 >user.list for user in `seq -w 10` do useradd wangyb$user password=`echo $RANDOM|md5sum|cut -... 阅读全文

posted @ 2016-09-06 23:46 王月波 阅读(1763) 评论(0) 推荐(0) 编辑

shell脚本,在指定目录下通过随机小写10个字母加固定字符串oldboy批量创建10个html文件。
摘要:[root@localhost wyb]# cat test10.sh #!/bin/bash #使用for循环在/test10目录下通过随机小写10个字母加固定字符串oldboy批量创建10个html文件 dir=/root/wyb/test10/ [ ! -d $dir ] && mkdir -p $dir for i in `seq 10` do touch $d... 阅读全文

posted @ 2016-09-06 22:59 王月波 阅读(4078) 评论(2) 推荐(0) 编辑

shell脚本,按字母出现频率降序排序。
摘要:[root@localhost oldboy]# cat file the squid project provides a number of resources toassist users design,implement and support squid installations. Please browsethe documentation and support section... 阅读全文

posted @ 2016-09-06 18:17 王月波 阅读(1834) 评论(0) 推荐(0) 编辑

shell脚本,按单词出现频率降序排序。
摘要:[root@localhost oldboy]# cat file the squid project provides a number of resources toassist users design,implement and support squid installations. Please browsethe documentation and support sections... 阅读全文

posted @ 2016-09-06 18:16 王月波 阅读(593) 评论(0) 推荐(0) 编辑

shell脚本,录制和回放终端的小工具script。
摘要:action.log和time.log这两个配置文件被当做script命令的参数。这两个文件可以随便命名。这里用time.log和action.log。其中time.log用于存储时序信息,描述每一个指令在何时运行;action.log用于存储命令信息输出。-t选项用于将时序数据导入stderr。2>用于stderr重定向到time.log。 [root@localhost ~]# script... 阅读全文

posted @ 2016-09-05 12:54 王月波 阅读(1202) 评论(0) 推荐(0) 编辑

shell脚本,alias别名命令用法。
摘要:[root@localhost ~]# alias alias cp='cp -i' alias mv='mv -i' alias rm='rm -i' [root@localhost ~]# [root@localhost ~]# [root@localhost ~]# [root@localhost ~]# [root@localhost ~]# alias cp alias cp=... 阅读全文

posted @ 2016-09-05 12:38 王月波 阅读(12331) 评论(0) 推荐(0) 编辑

shell脚本,一个字符一个字符输出。
摘要:[root@localhost wyb]# cat file 123 abc 456 456 def 1 23 5678 abc 789 789de f567 [root@localhost wyb]# cat fffile.sh #!/bin/bash cat file| while read line do for i in `seq 1 ${#line}` do a=`e... 阅读全文

posted @ 2016-09-04 22:53 王月波 阅读(2601) 评论(0) 推荐(0) 编辑

shell脚本,awk数组之如何处理多个文件。
摘要:[root@localhost awk]# seq 10|xargs -n 2 > file [root@localhost awk]# seq 10 -1 1|xargs -n 2 > file1 [root@localhost awk]# cat file 1 2 3 4 5 6 7 8 9 10 [root@localhost awk]# cat file1 10 9 8 7 6 5 4... 阅读全文

posted @ 2016-09-03 14:19 王月波 阅读(1030) 评论(0) 推荐(0) 编辑

shelll脚本,常见的脚本题目。
摘要:增加了一些需求 阅读全文

posted @ 2016-09-03 01:00 王月波 阅读(1218) 评论(0) 推荐(0) 编辑

shell脚本,提示用户输入一个用户名,如果存在;显示用户UID和SHELL信息;否则,则显示无此用户;显示完成之后,提示用户再次输入;如果是quit则退出;
摘要:[root@localhost wyb]# cat tishiuser.sh #!/bin/bash #提示用户输入一个用户名,如果存在;显示用户UID和SHELL信息;否则, #则显示无此用户;显示完成之后,提示用户再次输入;如果是quit则退出; echo 'Input `quit` to quit' while : do read -p "Please Input a us... 阅读全文

posted @ 2016-09-02 23:56 王月波 阅读(6860) 评论(0) 推荐(0) 编辑

shell脚本,配置文件加载顺序,以及什么时候加载。
摘要:在linux系统中,有/etc/profile,/etc/bashrc ,~/.bash_profile,~/bashrc这四个配置文件,这些文件,会自动的在某些时候加载,也就是点一下,一般都是些别名,特殊变量里面。四个有加载顺序,最先加载的是etc开头的/etc/profile,然后是/etc/. 阅读全文

posted @ 2016-09-02 00:45 王月波 阅读(1274) 评论(0) 推荐(0) 编辑

shell脚本,一个shell的启动流程。
摘要:#一个shell的启动流程 #shell有一些变量,叫做环境变量,这些变量是可以继承的, #比如父shell有$UID,子shell也可以有,而且继承父shell的。 #正常我们声明一个变量,a=1,在子shell里,a是空,自己声明的变量不能被继续。 如果我们自己声明变量,想让子shell也可以用 [root@localhost wyb]# cat a.sh #!/bin/bash e... 阅读全文

posted @ 2016-09-02 00:33 王月波 阅读(1391) 评论(0) 推荐(0) 编辑

shell脚本,怎么实现每次新开一个shell都输出一个提示语?
摘要:[root@localhost wyb]# cat test.sh echo -e "\033[32mhello,This is wangyuebo's shell\033[0m" echo -e "\033[32m`date`\033[0m" LANG=en echo -e "\033[32m`date` login at `hostname` `w`\033[0m" >>/etc/wang... 阅读全文

posted @ 2016-09-02 00:23 王月波 阅读(1792) 评论(0) 推荐(0) 编辑

shell脚本,文件里面的英文大小写替换方法。
摘要:[root@localhost wyb]# cat daxiaoxie qweBNMacb eeeDFSmkl svdIOPtyu [root@localhost wyb]# cat daxiaoxie |tr [a-zA-Z] [A-Za-z] QWEbnmACB EEEdfsMKL SVDiopTYU [root@localhost wyb]# 阅读全文

posted @ 2016-09-01 19:32 王月波 阅读(1453) 评论(0) 推荐(0) 编辑

shell脚本,100以内的质数有哪些?
摘要:[root@localhost wyb]# cat 9zhishu.sh #!/bin/bash for i in `seq 100` do for((j=2;j<=i-1;j++)) do [ $((i%j)) -eq 0 ] && break done [ $j -eq $i ] && echo $... 阅读全文

posted @ 2016-09-01 15:40 王月波 阅读(6308) 评论(1) 推荐(0) 编辑

导航

< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5
点击右上角即可分享
微信分享提示