• shell 处理文件脚本


    [root@centos-6 ~]# cat info_file.txt 
    lys:28:shanxi
    zhy:28:shanxi
    [root@centos-6 ~]# cat info_file2.txt 
    lys 28 shanxi
    zhy 28 shanxi
    [root@centos-6 ~]# cat print.sh 
    #!/bin/bash
    for i in `cat info_file.txt`
    
    do
    
    
    
    name=$(echo $i |awk -F : '{print $1}')
    age=$(echo $i |awk -F : '{print $2}')
    address=$(echo $i |awk -F : '{print $3}')
    
    echo "$name | $age |  $address "
    done
    [root@centos-6 ~]# cat while.sh 
    #!/bin/bash
    
    while read a b c
    
    do
    
    echo $a $b $c
    
    done <info_file2.txt
    [root@centos-6 ~]# sh print.sh 
    lys | 28 |  shanxi 
    zhy | 28 |  shanxi 
    [root@centos-6 ~]# sh while.sh 
    lys 28 shanxi
    zhy 28 shanxi
    [root@centos-6 ~]# 
    
    [root@centos-6 ~]# cat shift.sh 
    #!/bin/bash
    
    echo "print $1"
    
    [ "$1" = "lys" ] && shift 
    
    
    echo "print $1"
    
    ping -c 2 $1
    [root@centos-6 ~]# sh shift.sh  lys www.baidu.com
    print lys
    print www.baidu.com
    PING www.a.shifen.com (14.215.177.37) 56(84) bytes of data.
    64 bytes from 14.215.177.37: icmp_seq=1 ttl=128 time=147 ms
    64 bytes from 14.215.177.37: icmp_seq=2 ttl=128 time=144 ms
    
    --- www.a.shifen.com ping statistics ---
    2 packets transmitted, 2 received, 0% packet loss, time 5315ms
    rtt min/avg/max/mdev = 144.476/146.061/147.646/1.585 ms
    [root@centos-6 ~]# ^C
    [root@centos-6 ~]# sh shift.sh  zht www.baidu.com
    print zht
    print zht
    ping: unknown host zht
    [root@centos-6 ~]# 
    
  • 相关阅读:
    windows下安装redis
    十五oracle 触发器
    Flask 学习 六 大型程序结构
    Flask 学习 五 电子邮件
    Flask 学习 四 数据库
    Flask学习 三 web表单
    Flask学习 二 模板
    Flask学习 一 基本结构
    Python操作Redis
    Python操作MySQL
  • 原文地址:https://www.cnblogs.com/liuyoushui/p/6595752.html
Copyright © 2020-2023  润新知