技术改变生活

博客园 首页 新随笔 联系 订阅 管理

10 2020 档案

摘要:NR与FNR [root@x112 linshi]# awk '{print NR}' c.txt d.txt 1 2 3 4 5 6 7 8 [root@x112 linshi]# awk '{print FNR}' c.txt d.txt 1 2 3 4 1 2 3 4 [root@x112 l 阅读全文
posted @ 2020-10-24 20:17 小阿峰 阅读(126) 评论(0) 推荐(0)

摘要:使用awk方式: [root@x112 linshi]# cat 10_for.sh #!/bin/bash #describtion awk print first line ten time Line=$(cat c.txt|wc -l) awk '{if(NR==1) {for(i=1;i<= 阅读全文
posted @ 2020-10-24 17:58 小阿峰 阅读(154) 评论(0) 推荐(0)

摘要:oracle中查询某张表中的字段名,字段类型,是否为空,字段长度等信息 --更改某张表的字段类型长度 alter table bill_info modify IDCARD VARCHAR2 (30); --注意字段名(idcard)要大写; --查询某张表中的字段名,字段类型,是否为空,字段长度等 阅读全文
posted @ 2020-10-15 13:33 小阿峰 阅读(473) 评论(0) 推荐(0)

摘要:if格式{if(表达式){语句1;语句2;……}}{if(表达式){语句1;语句2,……}else{语句1;语句2,……}}{if(表达式){语句}else if(表达式){语句}else if(表达式){语句}else{语句}} awk -F: '{if($3<0 && $3<1000){i++} 阅读全文
posted @ 2020-10-06 21:21 小阿峰 阅读(341) 评论(0) 推荐(0)

摘要:awk是文本处理工具,功能小结如下: 1、条件表达式 [root@centos17 shell]# awk -F: '$3>1&&$3<3{print $0}' /etc/passwd daemon:x:2:2:daemon:/sbin:/sbin/nologin [root@centos17 sh 阅读全文
posted @ 2020-10-05 20:06 小阿峰 阅读(225) 评论(0) 推荐(0)

摘要:阶乘计算 版本一: [root@centos17 shell]# sh -v factorial.sh #!/bin/bash factorial() { factorial1=1 for((i=1;i<=5;i++));do factorial1=$((factorial1*i)) done ec 阅读全文
posted @ 2020-10-05 19:28 小阿峰 阅读(152) 评论(0) 推荐(0)

摘要:#!/bin/bash 官方推荐写法 #/usr/bin/env bash 最好的写法 #!/usr/bin/bash #!/bin/sh #!/usr/sh 后三种写法,根据不同的linux版本,路径会有所改变导致程序无法识别。可以使用#/usr/bin/env bash来替代。 阅读全文
posted @ 2020-10-05 18:56 小阿峰 阅读(244) 评论(0) 推荐(0)

摘要:关联数组 [root@centos17 shell]# cat shells_count.sh #!/bin/bash #login shell counts declare -A shells while read line do type=`echo $line|awk -F":" '{prin 阅读全文
posted @ 2020-10-05 11:09 小阿峰 阅读(261) 评论(0) 推荐(0)

摘要:对于表达式来说:i++是先赋值再加1,++i是先加1再赋值 对于i变量本身来说:结果一样 测试结果如下: [root@centos17 ~]# unset a [root@centos17 ~]# unset b [root@centos17 ~]# echo $a [root@centos17 ~ 阅读全文
posted @ 2020-10-04 19:32 小阿峰 阅读(1228) 评论(0) 推荐(0)

摘要:shell数组变量: 普通数组:只能使用整数作为数组索引 关联数组:可以使用字符串作为数组索引 数组变量与普通变量对比: 普通变量:只能存储一个值 数组变量:可以存储多个值 例如: name=playgame 变量 |p |l |a |y |g |a |m |e |0 |1 |2 |3 |4 |5  阅读全文
posted @ 2020-10-04 18:43 小阿峰 阅读(162) 评论(0) 推荐(0)

摘要:自定义变量,只在当前shell下生效。在编写脚本时,一般将公共的变量参数写到publish.sh脚本中,其他子功能的shell脚本,只需要执行. publish.sh 即可调用公共脚本里面定义的参数。所以,一般用不到环境变量。脚本变量调用关系如下图所示: 环境变量,在所有shell下都生效,可以在任 阅读全文
posted @ 2020-10-03 19:20 小阿峰 阅读(130) 评论(0) 推荐(0)